The code below, write the data section of the value, first saved to the stack, and then bounce out from the stack, put back the data section, after the execution, data section of the data, in turn.
Assume cs:code,ds:data,ss:stack
data segment
DW 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
data Ends
Stack segment
DW 0,0,0,0,0,0,0,0
stack ends
code segment
start:
mov ax,stack
mov ss , Ax
mov sp,16
mov ax,data
mov ds,ax
mov bx,0
mov cx,8
s:
push [BX]
add bx,2
loop s
mov bx,0
mov cx,8
s0:
pop [bx]
add bx,2
loop s0
mov ax,4c00h
int 21h
code ends
end Start
Generate EXE with MASM and link, then debug
Input u, display assembly instructions
Enter R to display the contents of the register and the next assembly instructions
Enter T, step through, and display the register contents and next assembly instructions
Enter G 0010 to display the contents of the register that executes to the 18d3:0010 at the cx,0008 before MOV
Enter d ds:0, display data segment + offset 0 and its subsequent data
As shown in the figure, the first row of data is the data in the data section of the program
Enter d ss:0 to display the data at the stack segment + offset 0 and back
Enter G 001a so that the first loop is executed and then enter D ss:0 to display the data in the stack
Looking at the first line, the data in the data segment has been pressed into the stack, then the result after the second loop has been executed.
Enter G 0027, then D ds:0, then D ss:0
See, the data in the data segment has been reversed.
Input T, single step to 21H interrupt
Enter P, run interrupt, and end the program
Enter Q to exit debug
Some of the above debug commands are often used by me at this time. University has learned assembly language, but has forgotten a lot, now review, by the way, to record, for later memories.