banner



How To Print The Content Of Register In Assembly

Associates - Registers


Processor operations mostly involve processing data. This data tin be stored in retention and accessed from thereon. However, reading data from and storing data into memory slows down the processor, equally it involves complicated processes of sending the data request across the control bus and into the memory storage unit of measurement and getting the information through the same channel.

To speed up the processor operations, the processor includes some internal retentivity storage locations, called registers.

The registers store data elements for processing without having to access the memory. A express number of registers are built into the processor chip.

Processor Registers

There are ten 32-bit and six 16-bit processor registers in IA-32 compages. The registers are grouped into three categories −

  • General registers,
  • Control registers, and
  • Segment registers.

The general registers are farther divided into the following groups −

  • Data registers,
  • Pointer registers, and
  • Index registers.

Data Registers

4 32-bit data registers are used for arithmetic, logical, and other operations. These 32-bit registers can be used in three ways −

  • Every bit consummate 32-scrap data registers: EAX, EBX, ECX, EDX.

  • Lower halves of the 32-bit registers can be used as four 16-chip data registers: AX, BX, CX and DX.

  • Lower and higher halves of the above-mentioned 4 xvi-bit registers can be used as 8 8-bit data registers: AH, AL, BH, BL, CH, CL, DH, and DL.

Data Registers

Some of these data registers have specific apply in arithmetical operations.

AX is the primary accumulator; information technology is used in input/output and well-nigh arithmetic instructions. For example, in multiplication operation, i 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 every bit the count register, equally the ECX, CX registers store the loop count in iterative operations.

DX is known as the data register. It is also used in input/output operations. It is likewise used with AX register forth with DX for multiply and dissever operations involving big values.

Pointer Registers

The pointer registers are 32-scrap EIP, ESP, and EBP registers and respective 16-flake right portions IP, SP, and BP. In that location are three categories of pointer registers −

  • Educational activity Pointer (IP) − The 16-bit IP register stores the get-go address of the next instruction to be executed. IP in association with the CS register (as CS:IP) gives the complete accost of the electric current instruction in the code segment.

  • Stack Arrow (SP) − The 16-chip SP register provides the offset value inside the program stack. SP in association with the SS annals (SS:SP) refers to exist current position of information or address within the programme stack.

  • Base of operations Arrow (BP) − The 16-bit BP register mainly helps in referencing the parameter variables passed to a subroutine. The accost in SS register is combined with the first in BP to get the location of the parameter. BP can also exist combined with DI and SI equally base register for special addressing.

Pointer Registers

Index Registers

The 32-bit 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. At that place are 2 sets of index pointers −

  • Source Index (SI) − It is used as source index for cord operations.

  • Destination Index (DI) − It is used as destination index for cord operations.

Index Registers

Control Registers

The 32-bit instruction pointer register and the 32-bit flags register combined are considered as the command registers.

Many instructions involve comparisons and mathematical calculations and change the condition of the flags and some other conditional instructions examination the value of these condition flags to take the control flow to other location.

The common flag $.25 are:

  • Overflow Flag (OF) − It indicates the overflow of a loftier-society bit (leftmost bit) of data after a signed arithmetic operation.

  • Direction Flag (DF) − It determines left or correct management for moving or comparing cord data. When the DF value is 0, the string functioning takes left-to-right management and when the value is set to 1, the string operation takes correct-to-left direction.

  • Interrupt Flag (IF) − It determines whether the external interrupts similar keyboard entry, etc., are to be ignored or processed. Information technology 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 single-stride mode. The DEBUG program we used sets the trap flag, so nosotros could step through the execution one instruction at a time.

  • Sign Flag (SF) − It shows the sign of the result of an arithmetic operation. This flag is prepare according to the sign of a data item following the arithmetics functioning. The sign is indicated past the high-order of leftmost chip. A positive result clears the value of SF to 0 and negative result sets it to 1.

  • Zero Flag (ZF) − It indicates the result of an arithmetics or comparison functioning. A nonzero issue clears the nada flag to 0, and a zero upshot sets it to one.

  • Auxiliary Carry Flag (AF) − Information technology contains the behave from bit 3 to bit 4 following an arithmetic operation; used for specialized arithmetics. The AF is set when a 1-byte arithmetic performance causes a conduct from chip 3 into bit 4.

  • Parity Flag (PF) − It indicates the total number of ane-bits in the result obtained from an arithmetic operation. An fifty-fifty number of ane-bits clears the parity flag to 0 and an odd number of one-bits sets the parity flag to 1.

  • Carry Flag (CF) − Information technology contains the comport of 0 or 1 from a high-order bit (leftmost) after an arithmetics functioning. Information technology also stores the contents of last bit of a shift or rotate operation.

The post-obit table indicates the position of flag bits in the 16-bit Flags annals:

Flag: O D I T S Z A P C
Bit no: 15 fourteen 13 12 11 ten 9 eight 7 vi 5 4 3 2 ane 0

Segment Registers

Segments are specific areas divers in a program for containing information, code and stack. There are three main segments −

  • Code Segment − It contains all the instructions to be executed. A 16-bit Lawmaking Segment register or CS register stores the starting address of the code segment.

  • Data Segment − Information technology contains data, constants and piece of work areas. A sixteen-bit Data Segment annals or DS annals stores the starting address of the information segment.

  • Stack Segment − It contains information and return addresses of procedures or subroutines. It is implemented as a 'stack' data structure. The Stack Segment register or SS register stores the starting address of the stack.

Apart from the DS, CS and SS registers, there are other extra segment registers - ES (extra segment), FS and GS, which provide additional segments for storing information.

In assembly programming, a programme needs to access the retention locations. All memory locations inside a segment are relative to the starting accost of the segment. A segment begins in an address evenly divisible past 16 or hexadecimal 10. And so, the rightmost hex digit in all such retention addresses is 0, which is not generally stored in the segment registers.

The segment registers stores the starting addresses of a segment. To become the exact location of data or instruction within a segment, an offset value (or deportation) is required. To reference whatsoever memory location in a segment, the processor combines the segment address in the segment annals with the kickoff value of the location.

Example

Look at the following uncomplicated program to understand the employ of registers in assembly programming. This programme displays 9 stars on the screen along with a simple message −

section	.text    global _start	 ;must exist declared 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,iv    ;arrangement call number (sys_write)    int	0x80     ;call kernel 	    mov	edx,ix    ;bulletin length    mov	ecx,s2   ;message to write    mov	ebx,i    ;file descriptor (stdout)    mov	eax,4    ;system call number (sys_write)    int	0x80     ;call kernel 	    mov	eax,ane    ;system call number (sys_exit)    int	0x80     ;phone call kernel 	 department	.data msg db 'Displaying 9 stars',0xa ;a bulletin len equ $ - msg  ;length of bulletin s2 times 9 db '*'        

When the higher up code is compiled and executed, it produces the following consequence −

Displaying 9 stars *********        

Useful Video Courses


Assembly Programming For All Platforms, Learn To Code

Video

VLSI, PLC, Microcontrollers, and Assembly Language

Video

Source: https://www.tutorialspoint.com/assembly_programming/assembly_registers.htm

Posted by: anthonylaralson.blogspot.com

0 Response to "How To Print The Content Of Register In Assembly"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel