Call and RET commands

Source: Internet
Author: User
Tags mul
1. The call and RET commands are both transfer commands, both of which modify the IP value or the Cs and IP value at the same time. They are often used in the design of subprograms. 2. the RET command uses the data in the stack to modify the IP content, so as to achieve near transfer. 3. The retf command uses the data in the stack to modify the Cs and IP content to achieve remote transfer. 4. When the CPU executes the RET command,

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

(2) (SP) = (SP) + 2

Equivalent to: when the pop ip executes the retf command,

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

(2) (SP) = (SP) + 2

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

(4) (SP) = (SP) + 2

This operation is equivalent to two steps when the pop ip pop cs5.cpu executes the call command: (1) Push the current IP address, Cs, and IP address to the stack; (2) Transfer (JMP) 6. the call command cannot implement short transfer. The call command implements transfer in the same way as the JMP command. 7. call label (after the current IP address is pressed to the stack, go to the label to execute the command) when the CPU executes the call command in this format, perform the following operations: (1) (SP) = (SP)-2 (SS) * 16 + (SP) = (IP) (2) (IP) = (IP) + when the 16-bit displacement call is executed with the "Call label", it is equivalent to the push ip jmp near PTR number 8. "Call far PTR label" implements inter-segment transfer. when the CPU executes the call command in this format, perform the following operations: (1) (SP) = (SP)-2 (SS) * 16 + (SP )) = (CS) (SP) = (SP)-2 (SS) * 16 + (SP) = (IP) (2) (CS) = segment address (IP) of the segment where the label belongs = when the CPU executes the "Call far PTR label" command, it is equivalent to push CS push ip jmp far PTR number 9. command Format: Call 16-bit Reg function: (SP) = (SP)-2 (SS) * 16 + (SP) = (IP) = (16-bit REG) when the CPU executes "Call 16-bit Reg", it is equivalent to: Push ip jmp 16-bit Reg 10. the call command of the transfer address in the memory can be in two formats. (1) Call word PTR memory unit address when the CPU executes the "Call word PTR memory unit address" command, it is equivalent to: Push ip jmp word PTR memory unit address (2) call dword ptr memory unit address when the CPU executes "Call dword ptr memory unit address", it is equivalent to: Push CS push ip jmp dword ptr memory unit address 11. call and RET can be used to implement the subroutine mechanism. The framework is as follows:
  1. Assume Cs: Code
  2. Code segment
  3. Start:
  4. :
  5. :
  6. Call sub1
  7. :
  8. :
  9. MoV ax, 4c00h
  10. Int 21 h
  11. Sub1:
  12. :
  13. :
  14. Call sub2
  15. :
  16. :
  17. RET
  18. Sub2:
  19. :
  20. :
  21. RET
  22. Code ends
  23. End start

 

12. mul is a multiplication command. Pay attention to two points when using Mul for multiplication. (1) Two multiplied numbers: the two multiplied numbers are either 8 bits or 16 bits. if it is 8 bits, it is put in Al by default, and the other is put in eight-bit reg or memory byte units; if it is 16 bits, one is put in ax by default, the other is placed in a 16-bit Reg over-memory unit. (2) Result: if it is an 8-bit multiplication, it is placed in ax by default; if it is a 16-bit multiplication, the result is placed in dx, and the low value is placed in ax. format: Mul Reg Mul memory unit example: (1) Calculate 100*10 mov Al, 100 mov BL, 10 Mul BL result: (ax) = 1000 (03e8h) (2) calculation results of 100*10000 mov ax, 100 mov BX, 10000 Mul Bx: (ax) = 4240 h, (dx) = 000fh (f4240h = 1000000) 13. call and RET commands support modular design in assembly language programming. 14. using registers to store parameters and results is the most common method. 15. for the transfer of batch data, we put it in the memory, and then put the first address of the memory control where they are located in the register and pass it to the required subroutine. (Lenovo: the pointer and array relationship of C) 16. when a register conflict occurs (for example, CX is used multiple times), the solution is to save all the values in the registers used in the subroutine at the beginning of the subroutine, resume before returning the subroutine (stack usage)

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.