在线二区人妖系列_国产亚洲欧美日韩在线一区_国产一级婬片视频免费看_精品少妇一区二区三区在线

鍍金池/ 教程/ Java/ Assembly 算術指令
Assembly 變量聲明
Assembly匯編 STOS指令
Assembly 條件
Assembly 尋址模式和MOV指令
Assembly匯編教程
Assembly - 什么是匯編語言
Assembly 循環(huán)
Assembly 內存段
Assembly匯編 宏
Assembly 寄存器
Assembly匯編 遞歸
Assembly匯編 CMPS指令
Assembly匯編 內存管理
Assembly匯編 LODS指令
Assembly 基本語法
Assembly匯編 過程
Assembly匯編 文件管理
Assembly匯編 數(shù)組
Assembly匯編 SCAS指令
Assembly 算術指令
Assembly 環(huán)境設置
Assembly匯編 字符串處理
Assembly 數(shù)字
Assembly 常量
Assembly匯編 MOVS指令
Assembly 邏輯指令
Assembly 系統(tǒng)調用

Assembly 算術指令

INC指令

INC指令是一個用于操作數(shù)遞增。它可以在一個單一的操作數(shù),可以是在一個寄存器或內存。

語法:

INC指令的語法如下:

INC destination

操作數(shù)目標可能是8位,16位或32位操作數(shù)。

例子:

INC EBX	     ; Increments 32-bit register
INC DL       ; Increments 8-bit register
INC [count]  ; Increments the count variable

DEC指令

DEC指令用于由一個操作數(shù)遞減。它可以在一個單一的操作數(shù),可以是在一個寄存器或內存。

語法:

DEC指令的語法如下:

DEC destination

操作數(shù)目標可以是8位,16位或32位操作數(shù)。

例子:

segment .data
	count dw  0
	value db  15
segment .text
	inc [count]
	dec [value]
	mov ebx, count
	inc word [ebx]
	mov esi, value
	dec byte [esi]

ADD和SUB指令

ADD和SUB指令用于執(zhí)行二進制數(shù)據(jù)字節(jié),字和雙字的大小,即簡單的加法/減法,8位,16位或32位操作數(shù)分別相加或相減。

語法:

ADD和SUB指令的語法如下:

ADD/SUB	destination, source

ADD/ SUB指令之間可能發(fā)生:

  • 寄存器到寄存器

  • 內存到寄存器

  • 寄存器內存

  • 寄存器到常量數(shù)據(jù)

  • 內存到常量數(shù)據(jù)

然而,像其他指令,內存到內存的操作是不可能使用ADD/ SUB指令。 ADD或SUB操作設置或清除溢出和進位標志。

例子:

下面的例子會從用戶要求的兩個數(shù)字,分別在EAX和EBX寄存器存儲的數(shù)字,增加值,并將結果存儲在一個內存位置'清晰度',并最終顯示結果。

SYS_EXIT  equ 1
SYS_READ  equ 3
SYS_WRITE equ 4
STDIN     equ 0
STDOUT    equ 1

segment .data 

    msg1 db "Enter a digit ", 0xA,0xD 
    len1 equ $- msg1 

    msg2 db "Please enter a second digit", 0xA,0xD 
    len2 equ $- msg2 

    msg3 db "The sum is: "
    len3 equ $- msg3

segment .bss

    num1 resb 2 
    num2 resb 2 
    res resb 1    

section	.text
    global _start    ;must be declared for using gcc
_start:    ;tell linker entry yiibai
    mov eax, SYS_WRITE         
    mov ebx, STDOUT         
    mov ecx, msg1         
    mov edx, len1 
    int 0x80                

    mov eax, SYS_READ 
    mov ebx, STDIN  
    mov ecx, num1 
    mov edx, 2
    int 0x80            

    mov eax, SYS_WRITE        
    mov ebx, STDOUT         
    mov ecx, msg2          
    mov edx, len2         
    int 0x80

    mov eax, SYS_READ  
    mov ebx, STDIN  
    mov ecx, num2 
    mov edx, 2
    int 0x80        

    mov eax, SYS_WRITE         
    mov ebx, STDOUT         
    mov ecx, msg3          
    mov edx, len3         
    int 0x80

    ; moving the first number to eax register and second number to ebx
    ; and subtracting ascii '0' to convert it into a decimal number
    mov eax, [number1]
    sub eax, '0'
    mov ebx, [number2]
    sub ebx, '0'

    ; add eax and ebx
    add eax, ebx
    ; add '0' to to convert the sum from decimal to ASCII
    add eax, '0'

    ; storing the sum in memory location res
    mov [res], eax

    ; print the sum 
    mov eax, SYS_WRITE        
    mov ebx, STDOUT
    mov ecx, res         
    mov edx, 1        
    int 0x80
exit:    
    mov eax, SYS_EXIT   
    xor ebx, ebx 
    int 0x80

上面的代碼編譯和執(zhí)行時,它會產(chǎn)生以下結果:

Enter a digit:
3
Please enter a second digit:
4
The sum is:
7

該程序用硬編碼的變量:

section	.text
    global _start    ;must be declared for using gcc
_start:    ;tell linker entry yiibai
	mov	eax,'3'
	sub     eax, '0'
	mov 	ebx, '4'
	sub     ebx, '0'
	add 	eax, ebx
	add	eax, '0'
	mov 	[sum], eax
	mov	ecx,msg	
	mov	edx, len
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel
	mov	ecx,sum
	mov	edx, 1
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel
	mov	eax,1	;system call number (sys_exit)
	int	0x80	;call kernel

section .data
	msg db "The sum is:", 0xA,0xD 
	len equ $ - msg   
	segment .bss
	sum resb 1

上面的代碼編譯和執(zhí)行時,它會產(chǎn)生以下結果:

The sum is:
7

MUL/ IMUL指令

有兩個指令乘以二進制數(shù)據(jù)。 MUL(乘)指令處理無符號數(shù)據(jù)和IMUL(整數(shù)乘法)處理有符號數(shù)據(jù)。這兩個指令影響進位和溢出標志。

語法:

MUL/ IMUL指令,語法如下:

MUL/IMUL multiplier

在這兩種情況被乘數(shù)是在累加器中,根據(jù)被乘數(shù)和乘數(shù)的大小,所產(chǎn)生的產(chǎn)物也被存儲在操作數(shù),大小取決于兩個寄存器。下面一節(jié)的解釋MULL有三種不同的情況指令:

SN Scenarios
1 When two bytes are multiplied

The multiplicand is in the AL register, and the multiplier is a byte in the memory or in another register. The product is in AX. High order 8 bits of the product is stored in AH and the low order 8 bits are stored in AL

8 bit Source Registers in MUL instruction

2 When two one-word values are multiplied

The multiplicand should be in the AX register, and the multiplier is a word in memory or another register. For example, for an instruction like MUL DX, you must store the multiplier in DX and the multiplicand in AX.

The resultant product is a double word, which will need two registers. The High order (leftmost) portion gets stored in DX and the lower-order (rightmost) portion gets stored in AX.

16 bit Source Registers in MUL instruction

3 When two doubleword values are multiplied

When two doubleword values are multiplied, the multiplicand should be in EAX and the multiplier is a doubleword value stored in memory or in another register. The product generated is stored in the EDX:EAX registers, i.e., the high order 32 bits gets stored in the EDX register and the low order 32-bits are stored in the EAX register.

32 bit Source Registers in MUL instruction

例子:

MOV AL, 10
MOV DL, 25
MUL DL
...
MOV DL, 0FFH	; DL= -1
MOV AL, 0BEH	; AL = -66
IMUL DL

例子:

下面的示例與2乘以3,并顯示結果:

section	.text
    global _start    ;must be declared for using gcc
_start:    ;tell linker entry yiibai

	mov	al,'3'
	sub     al, '0'
	mov 	bl, '2'
	sub     bl, '0'
	mul 	bl
	add	al, '0'
	mov 	[res], al
	mov	ecx,msg	
	mov	edx, len
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel
	mov	ecx,res
	mov	edx, 1
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel
	mov	eax,1	;system call number (sys_exit)
	int	0x80	;call kernel

section .data
msg db "The result is:", 0xA,0xD 
len equ $- msg   
segment .bss
res resb 1

上面的代碼編譯和執(zhí)行時,它會產(chǎn)生以下結果:

The result is:
6

DIV/IDIV 指令

除法運算產(chǎn)生兩個元素 - 一個商和余數(shù)。在乘法運算的情況下,不會發(fā)生溢出,因為雙倍長度的寄存器是用來保持產(chǎn)生。然而,在除法的情況下,可能會發(fā)生溢出。處理器產(chǎn)生一個中斷,如果發(fā)生溢出。

DIV(除)指令或無符號數(shù)據(jù)和IDIV(整數(shù)除法)用于有符號數(shù)據(jù)。

語法:

DIV / IDIV指令的格式為:

DIV/IDIV	divisor

被除數(shù)是在累加器。兩個指令可以處理8位,16位或32位操作數(shù)。該操作會影響所有的6個狀態(tài)標志。以下部分說明了三個例子的劃分有不同的操作數(shù)大?。?/p>

SN Scenarios
1 When the divisor is 1 byte

The dividend is assumed to be in the AX register (16 bits). After division, the quotient goes to the AL register and the remainder goes to the AH register.

DIV instruction

2 When the divisor is 1 word

The dividend is assumed to be 32 bits long and in the DX:AX registers. The high order 16 bits are in DX and the low order 16 bits are in AX. After division, the 16 bit quotient goes to the AX register and the 16 bit remainder goes to the DX register.

DIV instruction

3 When the divisor is doubleword

The dividend is assumed to be 64 bits long and in the EDX:EAX registers. The high order 32 bits are in EDX and the low order 32 bits are in EAX. After division, the 32 bit quotient goes to the EAX register and the 32 bit remainder goes to the EDX register.

DIV instruction

例子:

下面的例子8除于2。8被存儲在16位寄存器EAX和除數(shù)2被存儲在8位BL寄存器。

section	.text
    global _start    ;must be declared for using gcc
_start:    ;tell linker entry yiibai
	mov	ax,'8'
	sub     ax, '0'
	mov 	bl, '2'
	sub     bl, '0'
	div 	bl
	add	ax, '0'
	mov 	[res], ax
	mov	ecx,msg	
	mov	edx, len
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel
	mov	ecx,res
	mov	edx, 1
	mov	ebx,1	;file descriptor (stdout)
	mov	eax,4	;system call number (sys_write)
	int	0x80	;call kernel
	mov	eax,1	;system call number (sys_exit)
	int	0x80	;call kernel

section .data
msg db "The result is:", 0xA,0xD 
len equ $- msg   
segment .bss
res resb 1

上面的代碼編譯和執(zhí)行時,它會產(chǎn)生以下結果:

The result is:
4