实验三 转移指令跳转原理及其简单应用编程
实验任务1
assume cs:code, ds:data data segment x db 1, 9, 3 len1 equ $ - x y dw 1, 9, 3 len2 equ $ - y data ends code segment start: mov ax, data mov ds, ax mov si, offset x mov cx, len1 mov ah, 2 s1:mov dl, [si] or dl, 30h int 21h mov dl, ' ' int 21h inc si loop s1 mov ah, 2 mov dl, 0ah int 21h mov si, offset y mov cx, len2/2 mov ah, 2 s2:mov dx, [si] or dl, 30h int 21h mov dl, ' ' int 21h add si, 2 loop s2 mov ah, 4ch int 21h code ends end start

问题1: line27, 汇编指令 loop s1 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明是如何计算得到跳转后标号s1其后指令的偏移地址的。
根据076B:0019 E2F2 LOOP 000D
E2(Loop指令)F2(位移量的补码)即位移量为(F2)补为14,结果为下一条1bh-0dh=0dh
问题2:line44,汇编指令 loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明是如何计算得到跳转后标号s2其后指令的偏移地址的。
根据076B:0037 E2F0 LOOP 0029
同上,(F0)补为16,39h-10h=29h
在debug中进行调试观察的反汇编截图

实验任务2
assume cs:code, ds:data
data segment
dw 200h, 0h, 230h, 0h
data ends
stack segment
db 16 dup(0)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov word ptr ds:[0], offset s1
mov word ptr ds:[2], offset s2
mov ds:[4], cs
mov ax, stack
mov ss, ax
mov sp, 16
call word ptr ds:[0]
s1: pop ax
call dword ptr ds:[2]
s2: pop bx
pop cx
mov ah, 4ch
int 21h
code ends
end start
给出分析、调试、验证后,寄存器(ax) = 0021(bx) = 0026 (cx) = 076C 附上调试结果界面截图。

根据call指令的跳转原理,先从理论上分析,程序执行到退出(line31)之前,寄存器(ax) = ? 寄存器(bx) = ? 寄存器(cx) = ?
ax=21h; bx=26h; cx=076ch;
call word 入栈下一条即s1的ip,出栈给ax;
call dword指令依次入栈s2的cs和ip,ip出栈bx,cs出栈cx;
对源程序进行汇编、链接,得到可执行程序task2.exe。使用debug调试,观察、验证调试结果与理论分析结果是否一致。

一致;
实验任务3
assume cs:code, ds:data
data segment
x db 99, 72, 85, 63, 89,97,55
len equ $ - x
data ends
code segment
start:
mov ax, data
mov ds, ax
mov si, offset x
mov cx, len
s1: mov ah,0
mov al,[si]
push ax
call printNumber
call printSpace
pop ax
inc si
loop s1
mov ah, 4ch
int 21h
printNumber:
mov bl,10
div bl
mov bx,ax
mov ah,2
or bl, 30h
mov dl,bl
int 21h
or bh, 30h
mov dl,bh
int 21h
ret
printSpace:
mov ah,2
mov dl, ' '
int 21h
ret
code ends
end start

实验任务4
assume cs:code ds:data data segment str db 'try' len equ $ - str data ends code segment start: mov ax,data mov ds,ax mov si,offset str mov bh,0 mov bl,2 call printStr mov si,offset str mov bh,24 mov bl,4 call printStr mov ah,4ch int 21h printStr: mov cx,len mov ax,0b800h mov es,ax mov al,0a0h mul bh mov di,ax s:mov al,ds:[si] mov ah,bl mov es:[di],ax inc si add di,2 loop s ret code ends end start

实验任务5
assume cs:code ds:data data segment stu_no db '201983290120' len = $ - stu_no data ends code segment start: mov ax,data mov ds,ax mov bx,0 mov ax,0b800h mov es,ax mov cx,80 mov si,0f00h mov dl,'-' s1: mov es:[si],dl add si,2 loop s1 mov cx,len mov si,0f44h s2: mov dl,ds:[bx] mov es:[si],dl add si,2 inc bx loop s2 mov cx,2000 mov si,1 mov dl,17h s3: mov es:[si],dl add si,2 loop s3 mov ax,4c00h int 21h code ends end start


浙公网安备 33010602011771号