-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASM-Lang-Notes-Alison.txt
6204 lines (4639 loc) · 388 KB
/
ASM-Lang-Notes-Alison.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
175% Alison zoom https://alison.com/course/assembly-language-programming
::Assembly Programming Language (Alison Course Vids)::
-=Introduction, Setting Up and Registers=-
general registers, control registers, segment registers. data registers, pointer registers, index registers.
AX Accumulator BX Base CX Counter DX Data.
Pointer Registers: EIP ((Instruction Pointer) next instruction) ESP ((Stack Pointer) offset into the stack) EBP ((Base Pointer) arguments referencing variables passed to a function)
Index Registers: ESI (Source Index) ) EDI (Destination Index) ) string operations
Control Registers: Overflow Flag, Direction Flag, Interrupt Flag, Trap Flag, Sign Flag, Zero Flag, Auxiliary Carry Flag, Parity Flag, Carry Flag.
-=Address Modes and Variables=-
Kathleen Booth invented ASM /w John Von Neumann (Von Neumann architecture.) essentially opioids
.data .bss .text .stack.
int 80h (call to kernel)
Direct Offset Addressing:: var + 10
Indirect Memory Addressing:: mov ebp,hello mov ecx,ebp
mov destination,source
Allocating Space for Uninitiialized Data:: var1: db "Hi"
db = define 1 byte
dw = define word 2 bytes
dd = define doubleword 4 bytes
dq = define quadword 8 bytes
dt = define 10 bytes
Uninitiialized:: resb, resw, resd , resq, rest
Multiple Variable Initialization: zeros: TIMES 20 db "0"
-=Introduction, Registers & Variables – Lesson Summary=-
There are three main sections in any Assembly code; the data, text & bss sections.
Assembly splits the system memory into three main independent segments; data, code & stack segments. Constants and variables are stored in the data segment, while the stack segment stores data values that are passed to functions.
There are three main register types; general, control & segment registers. Segment registers are specific areas in a program for storing data, stack or code. General registers can be divided into data, pointer and index registers.
In immediate addressing, a constant is provided as a value, instead of a variable. In direct memory addressing, a variable is specified as value. In indirect memory addressing, a memory location is specified, in place of a value or a variable.
Data Segment stores constants & variables
Stack Segment stores data values that are passed to functions
The mov instruction is used to copy data from one location to another. Uninitialized data are variables that are created without an initial value. The times command is used to carry out multiple initializations
-=Constants & Arithmetic Instructions=-
Constants:: NUM_OF_ZEROES: equ 5 (above data)
%assign NUM_OF_ZEROES 4
%define STR "I am Batman!!!"
inc edx (increment by one (register or variable))
variable in assignment must be in [variable]
dec (decrement)
ADD::
section .bss
var1: resb, 4
var2: resb, 4
mov ebp, 5
mov esp, 2
add ebp, esp (stored result in ebp)
SUB::
mov ebp, 10
mov esp, 1
sub ebp,esp (subtracts 1 from 10)
MUL (eax is used to multiply)::
mov eax, 4
mov esp, 2
mul esp
mov esp, eax
mul is for unsigned (positive) data, imul for signed
DIV (The first operand of a mul or div command, must be EAX register)::
; 6 / 2 = 3
mov eax, 6
mov esp, 2
div esp (will assume eax is for first operand)
mov esp, eax
-=Binary Instructions & Jumping=-
AND:: (both bits must be 1 to be 1 result)
128 64 32 16 8 4 2 1
0 0 0 0 1 0 0 0 (8 decimal)
0 0 0 1 1 1 0 0 (28 decimal)
=======================
0 0 0 0 1 0 0 0 (result=8)
mov esp, 8
mov ebp, 28
mov esp, ebp
OR:: (works on binary level like AND. True if any are 1's)
128 64 32 16 8 4 2 1
0 0 0 0 1 0 1 0 (10 decimal)
0 0 0 0 0 0 1 1 (3 decimal)
=======================
0 0 0 0 1 0 1 1 (11 decimal)
mov esp, 10
mov ebp, 3
mov esp, ebp (end result will be stored in esp)
XOR (exclusive OR. True if either is 1 but not both)::
128 64 32 16 8 4 2 1
0 0 0 0 1 0 1 0 (10 decimal)
0 0 0 0 0 0 1 1 (3 decimal)
=======================
0 0 0 0 1 0 0 1 (9 decimal)
mov esp, 10
mov ebp, 3
xor esp, ebp (second operand doesn't have to be a register can be a number)
NOT (one operand only, flips inverts one operand's bits to opposite)::
128 64 32 16 8 4 2 1
0 0 0 0 1 0 1 0 (67 decimal)
=======================
0 0 0 0 1 0 0 1 (188 decimal)
mov esp, 67
not esp
CMP (comparison The cmp instructions compares the two operands that are passed to it. jump loop)::
mov esp, 1
LP1: (label)
inc esp
cmp esp, 5
mov eax,4
mov ebx,1
mov ecx,hello
mov edx,helloLen
int 80h
jle LP1
Unconditional Jump (infinite loop. when you want to jump & skip code /w if ? )::
jmp LP1
Conditional Jump (jump till condition is fulfilled):: jle till equal jl up until counter jge + dec is a countdown
ASCII System(rapidtablessciitable display capital A)::
section .bss
var1: resb 4
mov esp, 65
mov [var1], esp
-=Functions & Extras=-
Functions (grouping a few lines of code everytime you call function it initializes that code for eg. complex algorithm)::
epicPrint:
ret
call epicPrint
Stack DataStructure (LIFO like a stack of books last one you place is first one you pick up. Push to add to the stack Pop)::
mov ebp, 10
mov esi, 5
epicPrint:
push ebp (gets what's on ebp & pushes it onto the data stack = 10)
push esi ((top)5,10(bottom))
pop ebp (to remove & put back into register. ebp is 10 but you'll get 5 which is on top)
pop esi (when you goto pop & put the next item you'll get 10 which was originally in the ebp register)
mov ecx,hello
mov edx,ebp (print what's in ebp that length print 10 characters 5 times /w loop b4)
Hello WorlHello WorlHello WorlHello WorlHello Worl ()
now ~>>
HelloHello WorlHelloHello WorlHello (5,10,5,10,5 (they get swapped[interchanged] ebp was 10 becomes 5 (when on top ?!)))
Printing Numbers (+48=where 0 starts in ASCII)::
section .bss
var1: resb 4
mov esi, 5
mov [var1], esi
PrintNumber:
mov esi, [var1]
add esi, 48 (number cannot be added directly to variable)
mov [var1], esi
mov eax, 4 (syswrite)
mov ebx, 1 (output)
mov ecx, [var1] (print contents)
mov edx, helloLen
mov eax, 1
mov ebx, 0
int 80h
Function Recursion (A recursive function includes a call to itself. Factorial=number * times a number - 1 until you get to one)::
section .data
message db "Factorial of the number 3 = "
messageLen equ $- message
section .bss
fact resb 1
section .text
global _start
_start:
mov bx, 3 (mov=assigns the value of the second operand, to the first location)
call ProcessFactorial
add ax, 30h
mov [fact], ax
mov eax, 4
mov ebx, 1
mov ecx, message
mov edx, messageLen
int 80h
mov eax, 4
mov ebx, 1
mov ecx, fact
mov edx, 1
int 80h
mov eax, 1
mov ebx, 0
int 80h
ProcessFactorial:
cmp bl, 1
jg Calculate
mov ax, 1
ret
Calculate:
dec bl
call ProcessFactorial
inc bl
mul bl
ret (Assembly functions must be created with a return statement)
Strings::
section .data
str1 db "Hello Everyone", 10 (10 is line feed (new line))
strLen equ $- str1
mov eax, 4
mov ebx, 1
mov ecx, str1
mov edx, strLen
int 80h
Loops (w/o Jump Compare directly !)::
BITS 32
mov ecx, 5
l1:
push ecx
mov eax, 4
mov ebx, 1
move ecx, hello (ecx is repeatedoverwritten so you have to push & pop after the iteration of the loop)
mov edx. helloLen
int 80h
pop ecx
loop l1
Macros (run group of statements anywhere in the code)::
%macro EpicPrint 2 (2=number of arguments)
mov eax, 4
mov ebx, 1
mov ecx, %1
mov edx, %2
%endmacro
EpicPrint hello, helloLen (pass in the parameters)
System Calls::
-System call in EAX
-Store any values in the following registers: EBX, ECX, EDX, ESI, EDI, EBP
-Call the interrupt
-Any result is stored in the EAX register
-=Constants, Instructions and Functions – Lesson Summary=-
The ASCII character 10 adds a new line
Constants can be created with the equ, assign or define commands. Constants created with the assign command can be redefined, but cannot be reassigned.
The Stack data structure is used to store and retrieve data on a last in first out basis. The push command is used to add data to a stack, while the pop command removes the topmost data from a stack.
Function recursion describes a situation in which a function calls itself. The number of times a loop is needed to run, must be specified in the ECX register.
Macros are a set of instructions that can be initiated using a unique name, in any part of an Assembly code. Macros are created with the percentage (%) sign.
==++ GuidedHacking ASM++==
Registers
Most registers are now "general purpose" registers, but they each once had a specific purpose:
EAX = accumulator register for arithmetic such as adding/subtracting etc...
EBX = base register for indexing
ECX = counter register for keeping count of iterations
EDX = data register used in combination with EAX to do arithmetic
EIP = instruction pointer, this points to the current instruction that is executing
ESP = stack pointer
EBP = stack base pointer
ESI = source index register for string operations
EDI = destination index register for string operations
You will often see them used in the same capacity as they were originally intended, but it's not required, and with optimizations, the compiler will use whatever registers are the most efficient.
What about AX, AL, AH etc..?
These are just segments of the full size registers, which we will explain below. Sometimes you only need 1 or 2 bytes and you can pack 2-8 of these variables into one register to be more efficient.
What about RCX, RDX etc...?
RCX and similar are the 64 bit registers. They are the extended forms of the 32bit registers EAX, ECX, EDX etc.. But it's easy to recognize the different register representations.
Using the example of RAX:
RAX is the 64bit extended version of EAX
EAX is the 32bit extended version of AX
AX was a 16bit register at the time when registers were 16bit
You can still easily breakdown a 64 bit register value in hexadecimal to it's smaller components.
RAX is the total 64 bits
EAX is the lower 32 bits
AX is the lower 16 bits
AH represents the high 8 bits of AX
AL represents the low 8 bits of AX
Therefore if your 64 bit register contains: A0B1C2D3E4F5A6B7
EAX = E4F5A6B7
AX = A6B7
AH = A6
AL = B7
You can identify this visually very easily by opening the Windows Calculator and setting it to Programmer mode, hexadecimal mode and a QWORD value. Paste in "A0B1C2D3E4F5A6B7", then click QWORD several times to change it's type progressively smaller to see it's truncated values at each stage.
calc.gif
More about registers:
Assembly - Registers - Tutorialspoint
But Rake the stack is scary!
It sure can be, so let's break it down. Memory in the context of executing code has 4 classifications, the stack, the heap, code & the data segment which I kinda like to call "statically initialized data".
Code - Initialized at runtime and doesn't change. Modules like csgo.exe contain code that are static once loaded. This code exists on disk and can be resolved via relative offsets.
Data Segment - data that is initialized at the beginning of run time but the values these addresses contain can change, but many don't.
Heap - Dynamically created objects/variables are placed here. Using the "new" keyword in C++ allocates things on the heap, for efficiency reasons, these things don't need to exist on disk or in memory at runtime. They are created on demand when needed and deleted when no longer used.
Stack - this is the bit of memory (relatively small) that functions use for local variable storage.
The Stack
The stack is a part of memory that:
expands and shrinks as needed
is accessed in a "last in, first out" manner
represents local storage for functions
stores function arguments
stores return addresses
is used to preserve data in registers for later use
The Stack is actually a collection of stack frames. Each function has it's own stack frame. If function foo() calls bar() which calls snafu() and you're debugging snafu(), then foo and bar's stack frames are preserved in memory, but your current stack frame is currently defined by the ESP and EBP registers.
ESP = Extended Stack Pointer EBP = Extended Base Pointer
When a new function is to be called, the "function prologue" executes which preserves the previous stack frame, and sets up the stack frame for the next function. Depending on the calling convention it can be done by the caller or the callee, meaning before or after the "call" instruction executes.
Before the "function prologue" or "stack setup" occurs, ESP is pointing at the bottom of the current stack frame, when the setup occurs, EBP is made to point at the same location, and then ESP moves to a new position, which now represents the top of the next stack frame. So when a function prologue is completed, ESP points at the top of the current stack, and EBP points at the bottom of the current stack. The stack starts where ESP points and ends where EBP points. As you push and pop things onto the stack, the top of stack which ESP points to, moves. When you push onto the stack, it expands, when you pop, it shrinks.
RAKE THAT MAKES NO SENSE!
Why is the bottom of the stack a bigger number than the top!?!? And why in the name of god is it expanding down the address range?!
DONT ASK ME JUST WATCH THE DAMN VIDEOS
Excellent article here by Daax
Applied Reverse Engineering: The Stack - Reverse Engineering
All that stack talk makes my brain explode. Let's move onto something nicer.
Calling Conventions
stdcall, cdecl, thiscall etc... maybe you've heard of them? These define how the stack setup occurs, how the arguments are passed to the callee, how the stack unwinds and how the function returns.
The caller = the function that executes the call instruction
The callee = the function which is called by the caller
The functional prologue typically looks like this:
Code:Copy to clipboard
push ebp
mov ebp, esp
sub esp, n
Where n = the number of bytes used by the function for local storage. EBP is pushed onto the stack, preserving the address of the previous stack, then EBP is overwritten with the value in ESP, essentially zeroing out the stack, they both now point to the same address. Then ESP is moved to point at another address, by subtracting, to expand the stack frame to allow enough space for local variables and arguments in the new stack frame.
The Function epilogue looks like:
Code:Copy to clipboard
mov esp, ebp
pop ebp
ret
ESP is overwritten with the value in EBP, now they both point to the same address, zeroing out the stack. Then the old EBP(stored on the top of the stack) is popped off the stack into EBP, essentially resetting the stack frame to what it was before the current function was called.
cdecl = caller unwinds the stack
stdcall = the callee unwinds the stack
thiscall = essentially a stdcall, in which the callee cleans the stack the only difference being the this pointer is stored in ECX. thiscall is used for member functions. Virtual Table functions use this calling convention.
fastcall = first 2 arguments are passed in ECX and edx, the rest are pushed on the stack. The stack is cleaned simply by a series of pops and then a ret.
bss=(block starting symbol) aka variables data=constants db=databyte syscall instructions+operands.
Calling Game Functions: Guide - Guide on How to Call Game Functions ~~> https://guidedhacking.com/threads/guide-on-how-to-call-game-functions.11116/
How to Hook functions: Video Tutorial - C++ Detour / Hooking Function Tutorial for Game Hacking ~~> https://guidedhacking.com/threads/c-detour-hooking-function-tutorial-for-game-hacking.7930/
Callee refers to the function being called, and the caller is the function making the call.
The stack pointer (RSP/ESP/SP) is used to keep track of the top of the stack and the base pointer (RBP/EBP/BP) is used to keep track of the base/bottom of the stack. when data is pushed onto the stack, the stack pointer is decreased since the stack grew up towards lower addresses. Likewise, the stack pointer increases when data is popped off the stack. The base pointer has no reason to change when we push or pop something to/from the stack.
Big Endian - The most significant byte (far left) is stored first. This would be 0xDEADBEEF from the example.
Little Endian - The least significant byte (far right) is stored first. This would be 0xEFBEADDE from the example.
Square Brackets - Square brackets dereference in assembly. For example, [var] is the address pointed to by var. In other words, when using [var] we want to access the memory address that var is holding.
LEA - Ignore everything about square brackets when working with LEA. LEA is short for Load Effective Address and it's used for calculating and loading addresses.
JCC instructions are conditional jumps that jump based on the flags that are currently set.
==============what is an asm offset to stack StackOverflow What are offsets in Assembly and how do I use them?===============
Offsets are used in assembler to access data structures.
In the code you are using, you can see the base address being loaded. This is the starting address of a data structure.
The data structure will be defined some place, but not in the code. The definition is often as a table, showing, for example
4 bytes for this
2 bytes for that
4 bytes for something else
etc.
Modern processors use memory maps like this for input and output. Each device is "mapped" to a particular address. That's the base address in your code.
Without knowing what hardware is attached to your processor, we can't tell you what the data structure has in it. https://stackoverflow.com/questions/22677997/what-are-offsets-in-assembly-and-how-do-i-use-them
==============eof StackOverflow===============
=================What's the meaning of 'offset' instruction in assembly language? Quora============================
“Offset” is an assembler directive in x86 assembly language. It actually means “address” and is a way of handling the overloading of the “mov” instruction. Allow me to illustrate the usage -
mov si,offset variable
mov si,variable
The first line loads SI with the address of variable. The second line loads SI with the value stored at the address of variable.
As a matter of style, when I wrote x86 assembler I would write it this way -
mov si,offset variable
mov si,[variable]
The square brackets aren’t necessary, but they made it much clearer that I’m loading the contents rather than the address.
LEA is an instruction that I don’t think I ever used, not even once. All it does is load “offset variable” while adjusting the address between 16 and 32 bits as necessary. “LEA (16 bit register),(32 bit address)” loads the lower 16 bits of the address into the register, and “LEA (32 bit register),(16 bit address)” loads the 32 bit register with the address zero extended to 32 bits.
#2 Depends on the architecture, but assuming x86, as an instruction offset can be used to displace your code by an specific amount of bytes, and as a compiler operator it can indicate that you are referencing the address of a value and not the value itself.
But as for the second question, having the following lines:
mov ebx, offset Value
lea ebx, Value
Strictly speaking the result would be the same. But the offset in the first line gets translated on compilation time, ie you cannot refer to dynamically changing or calculated at runtime addresses the same way, you would have to use lea for that.
PS: I kept the answer simple and didn't go into much detail since I believe that's what you were looking for, but apologies if not. https://www.quora.com/Whats-the-meaning-of-offset-instruction-in-assembly-language
=============eof Quora=======================
==========================GeeksForGeeks Direct vs Indirect Addressing==================
1. Direct Addressing Mode: In direct addressing mode, the address field in the instruction contains the effective address of the operand and no intermediate memory access is required. Nowadays it is rarely used.
Example: Add the content of R1 and 1001 and store back to R1:
Add R1, (1001)
Here 1001 is the address where the operand is stored.
2. Indirect Addressing Mode: In Indirect addressing mode, the address field in the instruction contains the memory location or register where the effective address of the operand is present. It requires two memory access. It is further classified into two categories: Register Indirect, and Memory Indirect.
Example:
LOAD R1, @500
The above instruction is used to load the content of the memory location stored at memory location 500 to register R1. In other words, we can say, effective address is stored at memory location 500.
Advantages of Indirect Addressing = Availability of large address space. + It assists in passing arrays as parameters and implementing pointers. However, Requires two memory references + Address field contains reference of effective address. https://www.geeksforgeeks.org/difference-between-direct-and-indirect-addressing-modes/
====================eof GeeksForGeeks=========================
==============tutorialpoint Addressing modes=================
Assembly - Addressing Modes
Previous Page
Next Page
Most assembly language instructions require operands to be processed. An operand address provides the location, where the data to be processed is stored. Some instructions do not require an operand, whereas some other instructions may require one, two, or three operands.
When an instruction requires two operands, the first operand is generally the destination, which contains data in a register or memory location and the second operand is the source. Source contains either the data to be delivered (immediate addressing) or the address (in register or memory) of the data. Generally, the source data remains unaltered after the operation.
The three basic modes of addressing are −
Register addressing
Immediate addressing
Memory addressing
Register Addressing
In this addressing mode, a register contains the operand. Depending upon the instruction, the register may be the first operand, the second operand or both.
For example,
MOV DX, TAX_RATE ; Register in first operand
MOV COUNT, CX ; Register in second operand
MOV EAX, EBX ; Both the operands are in registers
As processing data between registers does not involve memory, it provides fastest processing of data.
Immediate Addressing
An immediate operand has a constant value or an expression. When an instruction with two operands uses immediate addressing, the first operand may be a register or memory location, and the second operand is an immediate constant. The first operand defines the length of the data.
For example,
BYTE_VALUE DB 150 ; A byte value is defined
WORD_VALUE DW 300 ; A word value is defined
ADD BYTE_VALUE, 65 ; An immediate operand 65 is added
MOV AX, 45H ; Immediate constant 45H is transferred to AX
Direct Memory Addressing
When operands are specified in memory addressing mode, direct access to main memory, usually to the data segment, is required. This way of addressing results in slower processing of data. To locate the exact location of data in memory, we need the segment start address, which is typically found in the DS register and an offset value. This offset value is also called effective address.
In direct addressing mode, the offset value is specified directly as part of the instruction, usually indicated by the variable name. The assembler calculates the offset value and maintains a symbol table, which stores the offset values of all the variables used in the program.
In direct memory addressing, one of the operands refers to a memory location and the other operand references a register.
For example,
ADD BYTE_VALUE, DL ; Adds the register in the memory location
MOV BX, WORD_VALUE ; Operand from the memory is added to register
Direct-Offset Addressing
This addressing mode uses the arithmetic operators to modify an address. For example, look at the following definitions that define tables of data −
BYTE_TABLE DB 14, 15, 22, 45 ; Tables of bytes
WORD_TABLE DW 134, 345, 564, 123 ; Tables of words
The following operations access data from the tables in the memory into registers −
MOV CL, BYTE_TABLE[2] ; Gets the 3rd element of the BYTE_TABLE
MOV CL, BYTE_TABLE + 2 ; Gets the 3rd element of the BYTE_TABLE
MOV CX, WORD_TABLE[3] ; Gets the 4th element of the WORD_TABLE
MOV CX, WORD_TABLE + 3 ; Gets the 4th element of the WORD_TABLE
Indirect Memory Addressing
This addressing mode utilizes the computer's ability of Segment:Offset addressing. Generally, the base registers EBX, EBP (or BX, BP) and the index registers (DI, SI), coded within square brackets for memory references, are used for this purpose.
Indirect addressing is generally used for variables containing several elements like, arrays. Starting address of the array is stored in, say, the EBX register.
The following code snippet shows how to access different elements of the variable.
MY_TABLE TIMES 10 DW 0 ; Allocates 10 words (2 bytes) each initialized to 0
MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX
MOV [EBX], 110 ; MY_TABLE[0] = 110
ADD EBX, 2 ; EBX = EBX +2
MOV [EBX], 123 ; MY_TABLE[1] = 123
The MOV Instruction
We have already used the MOV instruction that is used for moving data from one storage space to another. The MOV instruction takes two operands.
Syntax
The syntax of the MOV instruction is −
MOV destination, source
The MOV instruction may have one of the following five forms −
MOV register, register
MOV register, immediate
MOV memory, immediate
MOV register, memory
MOV memory, register
Please note that −
Both the operands in MOV operation should be of same size
The value of source operand remains unchanged
The MOV instruction causes ambiguity at times. For example, look at the statements −
MOV EBX, [MY_TABLE] ; Effective Address of MY_TABLE in EBX
MOV [EBX], 110 ; MY_TABLE[0] = 110
It is not clear whether you want to move a byte equivalent or word equivalent of the number 110. In such cases, it is wise to use a type specifier.
Following table shows some of the common type specifiers −
Type Specifier Bytes addressed
BYTE 1
WORD 2
DWORD 4
QWORD 8
TBYTE 10
https://www.tutorialspoint.com/assembly_programming/assembly_addressing_modes.htm
===============================eof TutorialsPoint==================================
https://ecomputernotes.com/computernetworkingnotes/naming-and-addressing/indirect-addressing https://www.quora.com/Whats-the-meaning-of-offset-instruction-in-assembly-language https://stackoverflow.com/questions/22677997/what-are-offsets-in-assembly-and-how-do-i-use-them https://www.ic.unicamp.br/~pannain/mc404/aulas/pdfs/Art%20Of%20Intel%20x86%20Assembly.pdf
What is indirect addressing mode and offset and displacement in assembly?
In assembly language programming, memory addressing modes are key. An instruction consists of two parts: an operation code (opcode) and an operand1. Indirect addressing mode uses a symbol such as “@” or “[]” to access the memory location pointed to by the contents of a register1.
Offset refers to a displacement from a base address. On x86 processors, this displacement is an offset from the beginning of a segment2. Displacement is similar to offset and refers to a fixed value added to the contents of an index register1.
What is segmentation in assembly language?
In assembly language programming, any program is divided into three memory segments: Code, Data and Stack1. The Code segment is where actual code is stored and is represented by the .text section. It mainly contains assembly language instructions and cannot be expanded once program execution begins1.
The Data segment is represented by the .data and .bss sections and is used to declare global and local variables1. The Stack segment is where data may be initialized at run-time
memory DC?
A memory DC (Device Context) is a special device context for bitmap operations that enables applications to place output in memory rather than sending it to an actual device1. It is an array of bits in memory that an application can use temporarily to store the color data for bitmaps created on a normal drawing surface1.
An application can create a memory DC by calling the CreateCompatibleDC function23. The original bitmap in a memory DC is simply a placeholder2.
What is protected mode in operating system?
Protected mode is an operational mode of x86-compatible central processing units (CPUs) that allows system software to use features such as virtual memory, paging and safe multi-tasking designed to increase an operating system’s control over application software1. It is also called protected virtual address mode1.
Protected mode was first introduced on Intel 80286 processors and provides access to addressing virtual memory, extended memory, and multitasking while protecting programs from overwriting one another in memory2.
============================BingAI tutorialspoint What are the different addressing modes in Assembly language programming?=======================
According to tutorialspoint.com, most assembly language instructions require operands to be processed. An operand address provides the location where the data to be processed is stored. Some instructions do not require an operand, whereas some other instructions may require one, two, or three operands.
Using different addressing modes, programmers can choose to reference data differently, as required by the program. Most assembly instructions that require operands follow this syntax, where inst is the instruction name, dest denotes the destination, and src denotes the source:
inst dest src
However, the operand may reside in memory, a register, or may be a constant1. https://www.educative.io/answers/what-are-addressing-modes-in-assembly-language https://www.tutorialspoint.com/assembly_programming/assembly_addressing_modes.htm https://microcontrollerslab.com/8086-microprocessor-addressing-modes-explained-with-assembly-examples/
================================
D.E. Knuth’s The Art of Computer Programming, Volume 3
========================BingAI What are some examples of addressing modes?===========================
According to tutorialspoint.com, there are several addressing modes in assembly language programming, including:
Immediate addressing mode
Register addressing mode
Direct addressing mode
Indirect addressing mode
Indexed addressing mode
Based addressing mode
Register indirect addressing mode
For more information on each of these modes, you can visit geeksforgeeks.org which provides a brief explanation of each mode with examples. https://www.geeksforgeeks.org/addressing-modes/
==================================ChatGPT================================
#Explain the different Assembly Addressing Modes with examples.
Assembly Addressing Modes are the ways in which data is accessed and stored in memory. They determine how the processor handles memory addressing.
1. Immediate Addressing:
This is a type of addressing mode where the instruction value itself holds the data. The data is not stored in memory but directly in the instruction itself. Example: MOV AL, 12
2. Direct Addressing:
In direct addressing, the instruction contains the address of the data. The data is stored in memory and the address of the data is present in the instruction. Example: MOV AL, [4000h]
3. Register Addressing:
In register addressing mode, the data is stored in a register and the instruction contains a reference to the register instead of the address. Example: MOV AL, CL
4. Indirect Addressing:
Indirect addressing uses a register or memory location to hold the address of the data. The address is not directly present in the instruction. Example: MOV AL, [SI]
5. Indexed Addressing:
Indexed addressing is a type of addressing mode where the address is calculated by adding a constant offset to the contents of a register. Example: MOV AL, [SI + 2]
Takes the expected branch, Tokenize it (split string) “After gotos, pointers are the next most dangerous element in a programming language.” “Pointers are to data structures what gotos are to control structures.” indirect jump, nested loops in ASM
===========================================
#Assembly Stack explanation include Indirect Addressing diagrams
In assembly language, the stack is a region of memory that is used for temporary storage of data. It is typically implemented as a Last-In-First-Out (LIFO) data structure, where data is pushed onto the top of the stack and popped off the top of the stack in reverse order.
Indirect addressing is a technique in assembly language that allows you to access memory using a pointer. Instead of specifying the memory address directly, you specify a register or memory location that contains the address of the data you want to access.
Here's an example of how indirect addressing can be used to manipulate the stack in x86 assembly:
cpp
Copy code
push eax ; push the value of the EAX register onto the stack
mov ecx, esp ; store the current stack pointer in the ECX register
add ecx, 4 ; add 4 bytes to the stack pointer
mov ebx, [ecx] ; use indirect addressing to load the value at the new top of the stack into EBX
In this example, we start by pushing the value of the EAX register onto the stack using the push instruction. This pushes a 4-byte value onto the stack and updates the stack pointer to point to the new top of the stack.
Next, we store the current stack pointer in the ECX register using the mov instruction. We then add 4 bytes to the stack pointer using the add instruction. This effectively moves the stack pointer down by 4 bytes, so that it now points to the value that was previously below the value we just pushed onto the stack.
Finally, we use indirect addressing to load the value at the new top of the stack into the EBX register. The [ecx] syntax is used to dereference the value in the ECX register and retrieve the value at that memory location.
Here's a diagram that shows the state of the stack and registers after each instruction in the example:
sql
Copy code
Initial state:
EAX: 0x12345678
ESP: 0x0012FFFC
+-------------+
| ... |
+-------------+
After "push eax":
EAX: 0x12345678
ESP: 0x0012FFF8
+-------------+
| 0x12345678 |
+-------------+
| ... |
+-------------+
After "mov ecx, esp":
EAX: 0x12345678
ECX: 0x0012FFF8
ESP: 0x0012FFF8
+-------------+
| 0x12345678 |
+-------------+
| ... |
+-------------+
After "add ecx, 4":
EAX: 0x12345678
ECX: 0x0012FFFC
ESP: 0x0012FFF8
+-------------+
| 0x12345678 |
+-------------+
| ... |
+-------------+
After "mov ebx, [ecx]":
EAX: 0x12345678
ECX: 0x0012FFFC
ESP: 0x0012FFF8
EBX: 0x...
+-------------+
| 0x12345678 |
+-------------+
| ... |
+-------------+
^
|
0x0012FFFC (new top of stack)
In summary, indirect addressing is a powerful technique in assembly language that allows you to manipulate the stack and other areas of memory using pointers. It is commonly used in conjunction with the stack to implement function calls, local variables, and other data structures.
=====================================
Assembly Bit Shifting explanation
Bit shifting is a technique used in low-level programming to manipulate the individual bits of binary data stored in memory. It is a fundamental operation in Assembly language, and can be used to perform a variety of tasks, such as bitwise logical operations, arithmetic operations, and data manipulation.
In Assembly, there are two types of bit shifting operations: logical and arithmetic. Logical bit shifting operations do not take into account the sign of the number being shifted, whereas arithmetic bit shifting operations do. Here is an overview of the two types of operations:
Logical bit shifting:
Left shift (SHL): Shifts all bits in a register or memory location to the left by a specified number of bits, filling the vacated bits with zeros.
Right shift (SHR): Shifts all bits in a register or memory location to the right by a specified number of bits, filling the vacated bits with zeros.
Arithmetic bit shifting:
Signed right shift (SAR): Shifts all bits in a register or memory location to the right by a specified number of bits, filling the vacated bits with the sign bit (i.e., the most significant bit of the original value).
Unsigned right shift (SHR): Shifts all bits in a register or memory location to the right by a specified number of bits, filling the vacated bits with zeros.
Here's an example of how to use logical bit shifting to perform a multiplication operation in Assembly:
Copy code
MOV AX, 10
SHL AX, 1
This code multiplies the value in the AX register by 2, by shifting all the bits to the left by 1 position. The resulting value in AX is 20.
And here's an example of how to use arithmetic bit shifting to perform a division operation in Assembly:
Copy code
MOV AX, -10
SAR AX, 1
This code divides the value in the AX register by 2, by shifting all the bits to the right by 1 position and filling the vacated bits with the sign bit. Since the value in AX is negative (-10), the resulting value is -5.
Overall, bit shifting is a powerful technique that can be used to perform a wide range of operations in Assembly language. However, it requires a good understanding of the underlying binary representation of data and the behavior of the different bit shifting operations.
===========================
#What is indirect addressing mode and offset and displacement in assembly?
In assembly language programming, memory addressing modes are key. An instruction consists of two parts: an operation code (opcode) and an operand1. Indirect addressing mode uses a symbol such as “@” or “[]” to access the memory location pointed to by the contents of a register1.
Offset refers to a displacement from a base address. On x86 processors, this displacement is an offset from the beginning of a segment2. Displacement is similar to offset and refers to a fixed value added to the contents of an index register1.
What is segmentation in assembly language?
In assembly language programming, any program is divided into three memory segments: Code, Data and Stack1. The Code segment is where actual code is stored and is represented by the .text section. It mainly contains assembly language instructions and cannot be expanded once program execution begins1.
The Data segment is represented by the .data and .bss sections and is used to declare global and local variables1. The Stack segment is where data may be initialized at run-time1.
=====================================
#What is a stack in assembly and how does it work?
A stack in assembly language is a group of memory locations in Read/Write (R/W) memory of a microcomputer that is used to store the contents of registers, operands, and memory addresses1. It operates on a Last-In-First-Out (LIFO) principle2.
The stack can be manipulated using various assembly language instructions such as push and pop. The push instruction stores data onto the stack while the pop instruction retrieves data from the stack3.
=====================================
#What is bit shifting in assembly language?
Bit shifting is an operation that moves bits to the left or right within a binary number. In assembly language, there are logical shift instructions that can be used with unsigned numbers. The bits that slide off the end disappear and spaces are filled with zeros1.
#How to do bit manipulation in assembly language?
Bit manipulation is the act of algorithmically manipulating bits or other pieces of data shorter than a word. In assembly language, you can use inline assembly code to manipulate bits. For example, an instruction that counts the number of 1’s or 0’s in the operand might be available1.
===================================
#XLAT opcode
XLAT (eXchange Look-Ahead Table) is an assembly language instruction that is used to access a certain byte in a lookup table and store the result in the accumulator. It is generally used to perform fast lookups or translations.
=====================================
#Dec2Bin
How to convert decimal to binary in Assembly Language?
The simplest way to convert a decimal number to binary in assembly language is to use the Bitwise AND operator and the shift right operator.
1. Start by initializing a register with the decimal value you want to convert.
2. Create a loop that will execute as long as the register is greater than 0.
3. Inside the loop, use the Bitwise AND operator to test the least significant bit of the register.
4. If the bit is 0, add a 0 to the result string. If the bit is 1, add a 1 to the result string.
5. Shift the register to the right by one bit, using the shift right operator.
6. Repeat steps 3-5 until the loop terminates.
7. The result string contains the binary representation of the decimal value.
======================================
#What does the assembly sbb instruction do with practical example.
The SBB instruction in x86 assembly subtracts the source operand and the carry flag from the destination operand, and stores the result in the destination operand. Here is an example of how the SBB instruction can be used in practice:
mov eax, 100 ; set eax to 100
mov ebx, 50 ; set ebx to 50
mov ecx, 1 ; set the carry flag to 1 (indicating a borrow)
sbb eax, ebx ; subtract ebx and the carry flag from eax
; the result (50) is stored in eax
; now eax = 50
sbb eax, ecx ; subtract the carry flag from eax
; since the carry flag is 1 and ecx is 1, the result is -2 (represented as 0xFFFFFFFF in 32-bit two's complement)
; now eax = 0xFFFFFFFF
In this example, we perform two calculations using the SBB instruction. First, we subtract the value in EBX (50) and the carry flag (1) from the value in EAX (100), which results in a new value of 50 in EAX. Then, we subtract the carry flag (1) from EAX, which results in a new value of -2 or 0xFFFFFFFF in EAX.
The SBB instruction is often used in conjunction with the ADC instruction to perform large integer arithmetic operations, and can also be useful in branching and loop constructs where arithmetic operations must be performed conditionally.
===========================================
#What are Indirect Jumps in Assembly with example code and explanations.
In assembly language, an indirect jump is a type of jump instruction that does not specify the address of the instruction to be executed next directly; instead, it retrieves the address from a register or memory location. This allows the address to be determined at runtime based on the value of the register or memory location.
Here is an example of how an indirect jump can be used in x86-64 assembly language:
section .data
target1 dd 0x12345678
target2 dd 0x90ABCDEF
section .text
global _start
_start:
mov eax, 1 ; set eax to 1
cmp eax, 0 ; compare eax to zero
jz target1 ; jump to target1 if eax is zero
jnz target2 ; jump to target2 if eax is not zero
target1:
mov ebx, [target1] ; set ebx to the value at target1
jmp [ebx] ; jump to the address stored in ebx
target2:
mov ecx, [target2] ; set ecx to the value at target2
jmp [ecx] ; jump to the address stored in ecx
In this example, the jmp instructions at target1 and target2 are indirect jumps because they do not specify the address of the next instruction directly. Instead, the address is retrieved from the memory locations target1 and target2, respectively. Depending on the value of eax, control will jump to either target1 or target2, where the jump will be resolved indirectly.
Note that in this example, the values stored at target1 and target2 are themselves addresses at which executable code is stored.
===========================================
#What is jcxz in Assembly?
jcxz is a conditional jump instruction in Assembly language that tests the value of the CX (or ECX for 32-bit code) register for zero, and jumps to a specified label if the value is zero. The syntax for the jcxz instruction is as follows:
jcxz label
Here, label is the label to which control will be transferred if the CX (or ECX) register is zero.
jcxz is useful for implementing loops where the number of iterations is stored in the CX (or ECX) register, as the instruction can be used to exit the loop when the counter reaches zero.
==========================================
#what is putcr in assembly?
In assembly language, PUTCR is a standard output routine that writes a carriage return and a line feed to the console. The PUTCR routine can be used to move the cursor to the beginning of the next line after a line of text has been printed. This output routine is part of the UCR Standard Library for 80x86 Assembly Language Programmers . It is commonly used in DOS-based assembly programming to provide formatted output to the console.
==============================================
#x86 Assembly Language Function different Parameter Passing examples.
In x86 assembly language, there are different ways to pass parameters to a function depending on the calling convention being used. The calling convention defines the rules for how function calls are made, including how parameters are passed and how the return value is handled. Here are some examples of parameter passing in x86 assembly language using different calling conventions:
CDECL (C declaration) calling convention:
In the cdecl calling convention, parameters are typically pushed onto the stack in reverse order before calling the function. The caller is responsible for cleaning up the stack after the function call. Here's an example:
assembly
Copy code
push param2
push param1
call myFunction
add esp, 8 ; Clean up the stack after the function call
In this example, param1 and param2 are pushed onto the stack in reverse order, and then the call instruction is used to call the myFunction function. After the function call, the add instruction is used to adjust the stack pointer (esp) to clean up the parameters from the stack.
STDCALL (Standard Call) calling convention:
In the stdcall calling convention, parameters are also pushed onto the stack in reverse order before calling the function. However, in this convention, the callee is responsible for cleaning up the stack after the function call. Here's an example:
assembly
Copy code
push param2
push param1
call myFunction
In this example, the parameter passing is similar to cdecl, but there is no need to explicitly clean up the stack after the function call. The callee takes care of cleaning up the parameters.
FASTCALL calling convention:
In the fastcall calling convention, some parameters may be passed in registers rather than on the stack for performance reasons. Typically, the first few parameters are passed in registers, and any remaining parameters are pushed onto the stack. Here's an example:
assembly
Copy code
mov ecx, param1
mov edx, param2
push param3
call myFunction
In this example, param1 is passed in the ecx register, param2 is passed in the edx register, and param3 is pushed onto the stack. The call instruction is then used to call the myFunction function.
These examples demonstrate different parameter passing techniques in x86 assembly language using different calling conventions. It's important to understand the calling convention being used when writing assembly code to ensure that the parameters are passed correctly and the stack is cleaned up properly after the function call.
============================================
#Explain what "mov rdi, qword ptr [rsi]" does in Assembly Language.
The instruction "mov rdi, qword ptr [rsi]" in assembly language is used to move a 64-bit value from the memory location pointed to by the source register RSI into the destination register RDI. Let's break down the components of this instruction:
"mov" is the mnemonic for the move instruction, which copies a value from one location to another.
"rdi" is the destination register, typically used for passing the first function argument or storing a memory address.
"qword ptr" indicates that the value being moved is a quadword (64 bits).
"[rsi]" represents the memory location being accessed. The source register RSI holds the memory address from which the value will be loaded.
In summary, the instruction "mov rdi, qword ptr [rsi]" copies a 64-bit value from the memory location pointed to by the RSI register and stores it in the RDI register. This is commonly used when working with function arguments or when accessing data stored in memory.
=============================================
#Explain what lea does in Assembly Language.
In assembly language, the "lea" instruction stands for "load effective address". Its primary purpose is to calculate the address of a memory operand and store it in a register, rather than loading the actual value from memory. The "lea" instruction performs arithmetic calculations on addresses, enabling the generation of complex memory addresses using simple operations.
The general syntax of the "lea" instruction is:
bash
Copy code
lea destination, source
Here's an explanation of what the "lea" instruction does:
It calculates the effective address of the source operand. The source operand can be a memory location, a register, or a combination of both.
It performs any necessary arithmetic calculations, such as addition, multiplication, or shifts, to determine the final address.
It stores the calculated address in the destination register.
For example, consider the following assembly code:
assembly
Copy code
lea eax, [ebx + 2*ecx]
In this code, the "lea" instruction calculates the effective address by adding the value of the EBX register to twice the value of the ECX register. The result is stored in the EAX register.
The "lea" instruction is often used for various purposes, such as:
Calculating addresses for array indexing or accessing data structures.
Generating pointers to data or functions.
Performing address calculations for efficient memory access.
By using the "lea" instruction, you can perform complex address calculations in a single instruction, saving time and improving code efficiency.
===========================================
#Explain Assembly Language FSCALE instruction with a working example.
The FSCALE instruction is used in x86 assembly language to multiply a floating-point value by 2 raised to the power of another floating-point value. It is often used to implement fixed-point arithmetic.
Here is an example of how to use the FSCALE instruction to multiply a floating-point value by a power of 2:
section .data
a: dd 2.0
b: dd 3.0
section .text
global _start
_start:
fld dword [a] ; load a onto the FPU stack
fld dword [b] ; load b onto the FPU stack
fscale ; multiply a by 2^b
fstp dword [a] ; store the result back in a
; do something with the result
In this example, the FSCALE instruction multiplies the floating-point value in a by 2 raised to the power of the floating-point value in b. The result is then stored back in a using the FSTP instruction. Note that the FSCALE instruction takes its operands from the top two values on the FPU stack, so we first load a and then b using the FLD instruction.
============================================
What does Assembly Language lesi instruction do?
The LESI instruction is a load effective address instruction, which is used to load the effective address of a memory location into a register. It is primarily used in assembly language programming to access memory locations
============================================
#List all regular expression syntax with minor explanations.
ChatGPT
Sure! Here is a list of regular expression syntax elements along with brief explanations:
Literal Characters: Any non-special character represents itself. For example, the letter "a" matches the letter "a" in the input.
Metacharacters:
Dot (.) matches any single character except a newline.
Caret (^) matches the start of a line or input.
Dollar sign ($) matches the end of a line or input.
Pipe (|) acts as an OR operator for alternatives.
Question mark (?) makes the preceding element optional.
Plus sign (+) matches one or more occurrences of the preceding element.
Asterisk (*) matches zero or more occurrences of the preceding element.
Character Classes:
Square brackets ([ ]) define a character class. For example, [abc] matches any single character "a", "b", or "c".
Dash (-) within a character class denotes a range. For example, [0-9] matches any digit.
Quantifiers:
Curly braces ({ }) define the exact number of occurrences. For example, a{3} matches "aaa".
Curly braces with a comma ({min, max}) define a range of occurrences. For example, a{2,5} matches "aa", "aaa", "aaaa", or "aaaaa".
Anchors:
Word boundary (\b) matches the position between a word character and a non-word character.
Not word boundary (\B) matches any position that is not a word boundary.
Lookahead (?=) and negative lookahead (?!), used for asserting the presence or absence of a pattern ahead, respectively.
Lookbehind (?<=) and negative lookbehind (?<!), used for asserting the presence or absence of a pattern behind, respectively.
Escape Sequences:
Backslash () is used to escape metacharacters and match them literally.
Backslash followed by a special character represents a predefined character class, such as \d for a digit or \s for whitespace.
Grouping and Capturing:
Parentheses (()) create a capturing group to capture and remember matched elements.
Backreference (\1, \2, etc.) refers to previously captured groups.
Non-capturing group (?:) groups subpatterns without capturing them.
Flags (modifiers):
Case-insensitive (i) allows matching regardless of case.
Global (g) allows multiple matches within the input string.
Multiline (m) changes the behavior of anchors (^ and $) to match the start and end of each line, instead of the entire input.
These are some common syntax elements used in regular expressions. Regular expressions can be more complex depending on the specific implementation or library you are using, but this list covers the basics.
============================================ChatGPT Stack Traversing