Assemble ret, retf and call

The ret instruction uses the data in the stack to modify the IP and realize the near transfer

1,(IP)=((SS)*16+(SP))

2,(SP)=(SP)+2

Equivalent to pop IP

 

The retf instruction modifies CS and IP with the data in the stack to achieve far transfer

1,(IP)=((SS)*16+(SP))

2,(SP)=(SP)+2

3,(CS)=((SS)*16+(SP))

4,(SP)=(SP)+2

Equivalent to pop IP, pop CS

 

The call instruction operates in two steps

1. Push the current IP or IP, CS into the stack

2. Transfer

call cannot implement short transfer, in addition, the method of call instruction to achieve transfer is the same as the principle of jmp instruction

The call label is equivalent to

push IP
jmp near ptr 标号

The call far ptr label implements inter-segment transfer, which is equivalent to

push CS
push IP
jmp far ptr 标号

call 16-bit reg, transfer address is in register

push IP
jmp 16位reg

call word ptr memory unit address

push IP
jmp word ptr 内存单元地址

call dword ptr memory location address

push CS
push IP
jmp dword ptr 内存单元地址

 

Using ret and call, bad programming of modules

CODES SEGMENT
    ASSUME CS:CODES,DS:DATAS,SS:STACKS
START:
    MOV AX,DATAS
    MOV DS,AX
 
    
    call fun1
    MOV AH,4CH
    INT 21H

fun1:
	...
	call fun2
	...
	ret

fun2:
	...
	ret
	
CODES ENDS
    END START

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325155761&siteId=291194637