Assembly - Registers寄存器

2023-10-24 14:32

本文主要是介绍Assembly - Registers寄存器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

转自:https://www.tutorialspoint.com/assembly_programming/assembly_registers.htm

这些寄存器的英文全称都有了对于理解汇编语言很有帮助!

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

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

The registers store data elements for processing without having to access the memory. A limited 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 architecture. The registers are grouped into three categories −

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

The general registers are further divided into the following groups −

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

Data Registers

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

  • As complete 32-bit data registers: EAX, EBX, ECX, EDX.

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

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

Data Registers

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

AX is the primary accumulator; it is used in input/output and most arithmetic instructions. For example, in multiplication operation, 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 register, as 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 also used with AX register along with DX for multiply and divide operations involving large values.

Pointer Registers

The pointer registers are 32-bit EIP, ESP, and EBP registers and corresponding 16-bit right portions IP, SP, and BP. There are three categories of pointer registers −

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

  • Stack Pointer (SP) − The 16-bit SP register provides the offset value within the program stack. SP in association with the SS register (SS:SP) refers to be current position of data or address within the program stack.

  • Base Pointer (BP) − The 16-bit 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 get the location of the parameter. BP can also be combined with DI and SI as base register for special addressing.

Pointer Registers

Index Registers

The 32-bit index 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 index pointers −

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

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

Index Registers

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 change the status of the flags and some other conditional instructions test the value of these status flags to take the control flow to other location.

The common flag bits are:

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

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

  • Interrupt Flag (IF) − It determines whether the external interrupts like 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 operation of the processor in single-step mode. The DEBUG program we used sets the trap flag, so we 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 set according to the sign of a data item following the arithmetic operation. The sign is indicated by the high-order of leftmost bit. 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 arithmetic or comparison operation. A nonzero result clears the zero flag to 0, and a zero result sets it to 1.

  • Auxiliary Carry Flag (AF) − It contains the carry from bit 3 to bit 4 following an arithmetic operation; used for specialized arithmetic. The AF is set when a 1-byte arithmetic operation causes a carry from bit 3 into bit 4.

  • Parity Flag (PF) − It indicates the total number of 1-bits in the result obtained from an arithmetic operation. 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.

  • Carry Flag (CF) − It contains the carry of 0 or 1 from a high-order bit (leftmost) after an arithmetic operation. It also stores the contents of last bit of a shift or rotate operation.

The following table indicates the position of flag bits in the 16-bit Flags register:

Flag:    ODITSZ A P C
Bit no:1514131211109876543210

Segment Registers

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

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

  • Data Segment − It contains data, constants and work areas. A 16-bit 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 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 data.

In assembly programming, a program needs to access the memory locations. All memory locations within a segment are relative to the starting address of the segment. A segment begins in an address evenly divisible by 16 or hexadecimal 10. So, the rightmost hex digit in all such memory 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 instruction within a segment, an offset value (or displacement) is required. To reference any memory location in a segment, the processor combines the segment address in the segment register with the offset value of the location.

Example

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

Live Demo

section	.textglobal _start	 ;must be declared for linker (gcc)_start:	         ;tell linker entry pointmov	edx,len  ;message lengthmov	ecx,msg  ;message to writemov	ebx,1    ;file descriptor (stdout)mov	eax,4    ;system call number (sys_write)int	0x80     ;call kernelmov	edx,9    ;message lengthmov	ecx,s2   ;message to writemov	ebx,1    ;file descriptor (stdout)mov	eax,4    ;system call number (sys_write)int	0x80     ;call kernelmov	eax,1    ;system call number (sys_exit)int	0x80     ;call kernelsection	.data
msg db 'Displaying 9 stars',0xa ;a message
len equ $ - msg  ;length of message
s2 times 9 db '*'

When the above code is compiled and executed, it produces the following result

 

DirectivePurposeStorage Space
DBDefine Byteallocates 1 byte
DWDefine Wordallocates 2 bytes
DDDefine Doublewordallocates 4 bytes
DQDefine Quadwordallocates 8 bytes
DTDefine Ten Bytes

allocates 10 bytes

choice		DB	'y'
number		DW	12345
neg_number	DW	-12345
big_number	DQ	123456789
real_number1	DD	1.234
real_number2	DQ	123.456

 

 

 

这篇关于Assembly - Registers寄存器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/275840

相关文章

寄存器B

MCS-51单片机的中央处理器包含运算部件和控制部件两部分。         1. 运算部件         运算部件以算术逻辑运算单元ALU为核心,包含累加器ACC、B寄存器、暂存器、标志寄存器PSW等许多部件,它能实现算术运算、逻辑运算、位运算、数据传输等处理。         算术逻辑运算单元ALU是一个8位的运算器,它不仅可以完成8位二进制数据加、减、乘、除等基本的算

士兰微 SC32F5432 通过配置寄存器方式 将管脚配成开漏输出模式和TTL输入模式

目录 前言: 士兰微电子介绍 士兰微 SC32F5432介绍 士兰微 SC32F5432 通过配置寄存器方式 将管脚配成开漏输出模式和TTL输入模式 开漏输出模式 TTL输入模式 前言: 下面是对我在工作时公司所使用的一款国产芯片(士兰微 SC32F5432)开发过程所遇到的一些问题的记录与解决。 士兰微电子介绍 杭州士兰微电子股份有限公司(600460)坐落于杭州

笔记 14 : 彭老师课本第 8 章, UART : 寄存器介绍 ,

(99) 继续介绍 uart 的关于通道的 一整套 寄存器, UCON 等: ++ 接着介绍寄存器 UTRSTAT : ++ 接着介绍读写数据的寄存器: ++ 设置 uart 的波特率,有关的寄存器: ++ (100) (101) 谢谢

AUXR-特殊功能寄存器(只写)

AUXR : Auxiliary Register(只写) MnemonicAddbitB7B6B5B4B3B2B1B0Reset ValueAUXR8EHname -  -  - - - -EXTRAMALEOFFxxxx,xx00 禁止ALE信号输出(应用示例供参考,C语言):sfr AUXR = 0x8e; //声明AUXR寄存器的地址AUXR = 0x01;//ALEOFF位置1

FPGA编程基础(一)--参数传递与寄存器使用

一、参数映射 参数映射的功能就是实现参数化元件。所谓的”参数化元件“就是指元件的某些参数是可调的,通过调整这些参数从而可实现一类结构类似而功能不同的电路。在应用中,很多电路都可采用参数映射来达到统一设计,如计数器、分频器、不同位宽的加法器以及不同刷新频率的VGA视频接口驱动电路等。 参数传递 参数传递就是在编译时对参数重新赋值而改变其值。传递的参数是子模块中定义的parameter,其传递方

【Live Archive】6393 Self-Assembly【强连通】

传送门:【Live Archive】6393 Self-Assembly 题目分析: 假设我们只用到向上或者向右的块,这样我们只要找到一个回路使得某个块可以和第一个块一样,那么我们就相当于找到了一个循环,这样就可以无限循环了。 但是我们要怎样去找这么一个环?考虑到必须是对应字母 X+,X− X^+,X^-才能建边,然后一个环中一定是多个一对一对的这样的对应字母组成的。 可以发现块的数量那么

【软件逆向】第38课,软件逆向安全工程师之操作标志寄存器实例,每天5分钟学习逆向吧!

在这些实例学习中,我们使用汇编指令来操作标志寄存器,并根据标志寄存器的状态进行条件分支。这些操作对于编写高效的汇编程序以及理解程序的行为至关重要 实例 1:使用 PUSHF 和 POPF 保存和恢复标志寄存器状态 section .text global _start _start: ; 初始化 AL 寄存器 MOV AL, 0xFF ; 对 AL 寄存器进行加一操作,这将导致 AL 寄存器的

C# Assembly

Ⅰ.Assembly应用场景 Assembly 是 .NET 中的一个核心概念,代表了编译后的代码库(如 .exe 或 .dll 文件)。在 C# 开发中,Assembly 有许多实际应用场景。以下是一些常见的场景和示例: 1. 动态加载程序集 在运行时加载和使用程序集,而不是在编译时引用。这在插件系统或模块化应用程序中非常有用。 应用场景: 插件系统:根据需要动态加载插件或模块。版本控

新路程------hi3516a 在应用层对寄存器的操作

由于在应用层没法用writel,所以参考himm.c写了一个设置,代码如下: void uart1_rtsn_high(void) {     void * pMem  = NULL;   pMem = memmap(0x201d0010, DEFAULT_MD_LEN);   *(U32*)pMem = 0xff; } 文件名是rs485.c,但是用arm-hisiv300-linux

【软件逆向】第30课,软件逆向安全工程师之(五)寄存器相对寻址,每天5分钟学习逆向吧!

寄存器相对寻址是汇编语言中的一种寻址方式,它结合了寄存器间接寻址和立即数偏移。在这种寻址方式中,操作数的有效地址是通过将一个寄存器的内容与一个固定的偏移量(立即数)相加来得到的。以下是关于寄存器相对寻址的详细信息: 寄存器相对寻址的特点: 操作数地址是寄存器内容与偏移量的和:有效地址是寄存器的内容加上一个固定的立即数偏移量。灵活且具体:提供了对特定内存位置的间接访问,同时允许通过改变寄存器的内