How To Clear All My Registers In Assembly
Assembly - Registers
Processor operations mostly involve processing data. This information tin be stored in retentivity and accessed from thereon. Even so, reading data from and storing data into memory slows downward the processor, as information technology involves complicated processes of sending the data request beyond the command bus and into the memory storage unit of measurement and getting the information through the same aqueduct.
To speed upwardly the processor operations, the processor includes some internal memory storage locations, called registers.
The registers shop data elements for processing without having to access the retentiveness. A limited number of registers are congenital into the processor flake.
Processor Registers
There are ten 32-bit and six 16-bit processor registers in IA-32 compages. The registers are grouped into iii categories −
- Full general registers,
- Control registers, and
- Segment registers.
The full general registers are further divided into the following groups −
- Data registers,
- Pointer registers, and
- Alphabetize registers.
Data Registers
Four 32-fleck information registers are used for arithmetics, logical, and other operations. These 32-bit registers can exist used in three ways −
-
As consummate 32-bit information registers: EAX, EBX, ECX, EDX.
-
Lower halves of the 32-fleck registers can be used equally four 16-scrap information registers: AX, BX, CX and DX.
-
Lower and higher halves of the in a higher place-mentioned four sixteen-chip registers can be used as 8 eight-bit data registers: AH, AL, BH, BL, CH, CL, DH, and DL.
Some of these data registers have specific use in arithmetical operations.
AX is the principal accumulator; it is used in input/output and virtually arithmetic instructions. For example, in multiplication performance, one operand is stored in EAX or AX or AL register according to the size of the operand.
BX is known as the base register, as it could be used in indexed addressing.
CX is known as the count annals, as the ECX, CX registers store the loop count in iterative operations.
DX is known as the data register. Information technology is also used in input/output operations. It is also used with AX register forth with DX for multiply and divide operations involving big values.
Pointer Registers
The arrow registers are 32-bit EIP, ESP, and EBP registers and corresponding 16-bit right portions IP, SP, and BP. At that place are iii categories of pointer registers −
-
Educational activity Pointer (IP) − The 16-bit IP register stores the beginning address of the next instruction to be executed. IP in association with the CS annals (as CS:IP) gives the consummate address of the electric current instruction in the lawmaking segment.
-
Stack Pointer (SP) − The 16-bit SP annals provides the showtime value within the program stack. SP in association with the SS register (SS:SP) refers to be current position of data or accost within the plan stack.
-
Base Pointer (BP) − The 16-chip BP register mainly helps in referencing the parameter variables passed to a subroutine. The address in SS register is combined with the offset in BP to go the location of the parameter. BP can also be combined with DI and SI as base register for special addressing.
Alphabetize Registers
The 32-scrap alphabetize registers, ESI and EDI, and their 16-bit rightmost portions. SI and DI, are used for indexed addressing and sometimes used in addition and subtraction. There are two sets of alphabetize pointers −
-
Source Alphabetize (SI) − It is used as source index for string operations.
-
Destination Index (DI) − It is used as destination index for string operations.
Control Registers
The 32-bit instruction pointer register and the 32-bit flags register combined are considered as the control registers.
Many instructions involve comparisons and mathematical calculations and alter the status of the flags and another provisional instructions test the value of these status flags to take the control flow to other location.
The common flag $.25 are:
-
Overflow Flag (OF) − Information technology indicates the overflow of a loftier-lodge bit (leftmost bit) of information after a signed arithmetic performance.
-
Direction Flag (DF) − It determines left or correct direction for moving or comparing string data. When the DF value is 0, the string operation takes left-to-right management and when the value is fix to 1, the string operation takes correct-to-left management.
-
Interrupt Flag (IF) − It determines whether the external interrupts similar keyboard entry, etc., are to be ignored or processed. It disables the external interrupt when the value is 0 and enables interrupts when set to 1.
-
Trap Flag (TF) − It allows setting the performance of the processor in unmarried-step manner. The DEBUG program we used sets the trap flag, so nosotros could step through the execution one teaching at a time.
-
Sign Flag (SF) − Information technology shows the sign of the consequence of an arithmetic functioning. This flag is gear up according to the sign of a data item following the arithmetic operation. The sign is indicated by the high-order of leftmost chip. A positive effect clears the value of SF to 0 and negative effect sets it to one.
-
Zero Flag (ZF) − It indicates the result of an arithmetic or comparing performance. A nonzero consequence clears the nix flag to 0, and a zero result sets it to 1.
-
Auxiliary Carry Flag (AF) − Information technology contains the comport from bit three to scrap 4 following an arithmetic performance; used for specialized arithmetic. The AF is set when a 1-byte arithmetics operation causes a carry from bit 3 into bit iv.
-
Parity Flag (PF) − It indicates the full number of 1-$.25 in the result obtained from an arithmetic performance. An even number of 1-bits clears the parity flag to 0 and an odd number of 1-bits sets the parity flag to 1.
-
Behave Flag (CF) − It contains the behave of 0 or i from a high-order bit (leftmost) later on an arithmetic operation. It also stores the contents of last bit of a shift or rotate operation.
The following tabular array indicates the position of flag $.25 in the 16-bit Flags register:
Flag: | O | D | I | T | S | Z | A | P | C | |||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Bit no: | 15 | 14 | 13 | 12 | eleven | 10 | 9 | viii | 7 | 6 | 5 | iv | 3 | 2 | i | 0 |
Segment Registers
Segments are specific areas divers in a program for containing information, code and stack. There are three primary segments −
-
Lawmaking Segment − Information technology contains all the instructions to be executed. A 16-scrap Code Segment register or CS register stores the starting address of the code segment.
-
Data Segment − It contains data, constants and work areas. A xvi-flake Data Segment register or DS register stores the starting address of the data segment.
-
Stack Segment − It contains data and return addresses of procedures or subroutines. It is implemented as a 'stack' data structure. The Stack Segment annals or SS annals stores the starting address of the stack.
Apart from the DS, CS and SS registers, in that location are other extra segment registers - ES (extra segment), FS and GS, which provide additional segments for storing data.
In assembly programming, a plan needs to admission the memory locations. All retentivity locations within a segment are relative to the starting address of the segment. A segment begins in an address evenly divisible by sixteen or hexadecimal x. So, the rightmost hex digit in all such retentiveness addresses is 0, which is not generally stored in the segment registers.
The segment registers stores the starting addresses of a segment. To get the exact location of data or education within a segment, an offset value (or displacement) is required. To reference whatsoever retention location in a segment, the processor combines the segment address in the segment register with the first value of the location.
Case
Await at the post-obit simple program to empathise the use of registers in assembly programming. This plan displays 9 stars on the screen along with a uncomplicated message −
section .text global _start ;must be alleged for linker (gcc) _start: ;tell linker entry point mov edx,len ;message length mov ecx,msg ;message to write mov ebx,1 ;file descriptor (stdout) mov eax,4 ;system call number (sys_write) int 0x80 ;call kernel mov edx,9 ;message length mov ecx,s2 ;message to write mov ebx,ane ;file descriptor (stdout) mov eax,iv ;system call number (sys_write) int 0x80 ;call kernel mov eax,one ;system call number (sys_exit) int 0x80 ;call kernel section .data msg db 'Displaying 9 stars',0xa ;a bulletin len equ $ - msg ;length of message s2 times 9 db '*'
When the above lawmaking is compiled and executed, information technology produces the following consequence −
Displaying 9 stars *********
Useful Video Courses
Video
Video
Source: https://www.tutorialspoint.com/assembly_programming/assembly_registers.htm
Posted by: hendersonention.blogspot.com
0 Response to "How To Clear All My Registers In Assembly"
Post a Comment