Assembly language--call and RET directives

Source: Internet
Author: User
Tags mul

I. RET and RETF

We use the assembly syntax to explain the ret and RETF directives:

When the CPU executes a RET instruction, it is equivalent to:

    • Pop IP

When the CPU executes the RETF instruction, it is equivalent to:

    • Pop IP (the general IP is at the low address)
    • POP CS (cs at high address)

Second, call command

The CPU executes a call instruction and performs two steps:

(1) Press the current IP or CS and IP into the stack;

(2) Transfer.

The call instruction is not able to achieve short transfer within the paragraph , in addition to the method of calling instruction to achieve the same principle as the JMP instructions, in the following subsections, we give the different methods of transferring the destination address as the main line, explaining the major application format of the called Command.

Intra-segment transfer

Instruction format: Calllabel

The CPU executes the above instruction equivalent to:

Push IP

JMP near PTR label

Inter-segment Transfer

Instruction format: Call farptr designator

When the CPU executes the above instruction, it is equivalent to:

Push CS

Push IP

JMP far PTR designator

Call instructions for transferring addresses in registers

Instruction style: Call16-bit register

When the CPU executes the above instruction, it is equivalent to:

Push IP

JMP 16-bit registers

Transfer address in-memory call instruction

(1) Call Word PTR memory unit address

Compilation Grammar Explanation:

Push IP

JMP Word PTR memory cell address

(2) Call DWORD PTR memory Unit address

Compilation Grammar Explanation:

Push CS

Push IP

JMP DWORD PTR memory Unit address

MUL directive

Mul is a multiplication instruction that uses mul to do multiplication:

(1) Two numbers multiplied: either 8-bit or 16-bit.

8 bits: Al and 8-bit registers or memory byte units;

16-bit: Ax and 16-bit registers or memory word cells.

When using Mul-block multiplication:

(2) Results

8-bit: in AX;

16-bit: DX (high) and Ax (low).

(3) Instruction style

MUL Reg

Mul Memory Unit

(4) The memory unit can be given by different addressing methods

Mul byte ptr ds:[0]

Meaning: (Ax) = (AL) * ((DS) *16+0);

Mul word ptr [bx+si+8]

The meaning is:

(AX) = (AX) * ((DS) *16+ (BX) + (SI) +8) Results of low 16 bits;

(dx) = (AX) * ((DS) *16+ (BX) + (SI) +8) Results of high 16 bits;

Example: Calculating 100*10000

100 is less than 255, can 10000 is greater than 255, so 16-bit multiplication must be done, the program is as follows:

MOV ax,100

MOV bx,10000

Mul BX

Results: (AX) =4240h, (DX) =000fh (f4240h=1000000)

Method One:

Method Two: Always use JCXZ to jump out of the loop when the value of CX is 0 (benefit, do not set CX size)

Method Three: Register is limited, so we can use the stack to hold the data

1Capital  : push  CX 2           push  si 3          4  Change : movCl,[si]5          movCh06          JcxzOK7           andbyte ptr [si],11011111b8          Incsi9          jmp Short ChangeTen           One      OK:  pop  si  A           pop  CX  -          ret

Assembly language--call and RET directives

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.