“Assembly Language”, 3rd Edition by Wang Shuang
Chapter 10: CALL and RET Instructions
Checkpoint 10.1 (Page 191)
Complete the program to execute instructions starting from memory address 1000:0000.
assume cs:codestack segment db 16 dup(0)stack endscode segment start: mov ax, stack mov ss, ax mov sp, 16 mov ax, ______ push ax mov ax, ______ push ax retfcode endsend start
————————-
Reference Answer
Analysis: First, it is important to clarify that when representing a memory address like “1000:0000”, the value is in hexadecimal, meaning 1000 represents hexadecimal 1000H rather than decimal 1000.
Secondly, the retf instruction relies on the stack to achieve far transfer by modifying both CS and IP simultaneously. The word unit that is popped from the stack first is assigned to IP, and the word unit that is popped second is assigned to CS. Therefore, when pushing onto the stack, the order must be reversed, with CS pushed first and IP pushed second. Thus, the code to be completed is:
mov ax, 1000H
mov ax, 0
Note: 1000 should be written as 1000H. In assembly source programs, hexadecimal values must have the suffix H (case insensitive), and binary values must have the suffix B (case insensitive). If no suffix is added, it is assumed to be decimal data.