实验3 转移指令跳转原理及其简单应用编程
实验任务1
源代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
assume cs:code, ds:datadata segmentx db 1, 9, 3len1 equ $ - x ; 符号常量, $指下一个数据项的偏移地址,这个示例中,是3y dw 1, 9, 3len2 equ $ - y ; 符号常量, $指下一个数据项的偏移地址,这个示例中,是9data endscode segmentstart:mov ax, datamov ds, axmov si, offset x ; 取符号x对应的偏移地址0 -> simov cx, len1 ; 从符号x开始的连续字节数据项个数 -> cxmov ah, 2s1:mov dl, [si]or dl, 30hint 21hmov dl, ' 'int 21h ; 输出空格inc siloop s1mov ah, 2mov dl, 0ahint 21h ; 换行mov si, offset y ; 取符号y对应的偏移地址3 -> simov cx, len2/2 ; 从符号y开始的连续字数据项个数 -> cxmov ah, 2s2:mov dx, [si]or dl, 30hint 21hmov dl, ' 'int 21h ; 输出空格add si, 2loop s2mov ah, 4chint 21hcode endsend start |



问题1:
line27, 汇编指令 loop s1 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明 是如何计算得到跳转后标号s1其后指令的偏移地址的。
答:loop s1的机器码为E2F2。跳转的位移量为-14。
loop指令后的第一个字节的偏移地址为:001B,而标号s1处的偏移地址为:000D,位移量=13(000D)-27(001B)=-14(补码表示为F2)。所以其跳转的位移量是-14。
问题2:
line44,汇编指令 loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明 是如何计算得到跳转后标号s2其后指令的偏移地址的。
答:loop s2的机器码为E2F0。跳转的位移量为-16。
Loop指令后的第一个字节的偏移地址为:0039,而标号s2处的偏移地址为:0029,位移量=41(0029)-57(0039)=-16(补码表示为F0)。所以其跳转的位移量为-16。
实验任务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
① 根据call指令的跳转原理,先从理论上分析,程序执行到退出(line31)之前,寄存器(ax) = ? 寄存器 (bx) = ? 寄存器(cx) = ?
ax=0021H,bx=0026H,cx=076CH.
问题2:
对源程序进行汇编、链接,得到可执行程序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 ax, 0b800h
mov es, ax
mov bx,0
mov si,0
mov cx,len
s:mov al, [si]
mov ah, 0
call printNumber
add bx, 2
call printSpace
inc bx
inc si
loop s
mov ax, 4c00h
int 21h
printNumber:
mov dl, 10
div dl
or al, 30h
or ah, 30h
mov dh, ah
mov ah, 2
mov dl, al
int 21h
mov dl, dh
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 dh, 0
mov bl, 2
mov si, 0
mov ax, 0b800h
mov es, ax
call printStr
mov dh, 24
mov bl, 4
mov si, 0
call printStr
mov ax,4c00h
int 21h
printStr:
mov al, 160
mul dh
mov dx, ax
mov al, bl
mov bx, dx
mov cx, len
s: mov dl, [si]
mov es:[bx], dl
inc bx
mov es:[bx], al
inc bx
inc si
loop s
ret
code ends
end start
实验结果:

实验任务5
源代码:
assume cs:code, ds:data
data segment
stu_no db '20192375030'
len = $ - stu_no
data ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, 0b800h
mov es, ax
mov si, 1
mov dl, 17h
mov cx, 2000
bc:mov es:[si], dl
add si, 2
loop bc
mov dh, 24
mov al, 160
mul dh
mov bx, ax
call minus
mov si, 0
mov cx, len
s1:mov dl, [si]
mov es:[bx], dl
add bx, 2
inc si
loop s1
call minus
mov ax, 4c00h
int 21h
minus:
mov dl, '-'
mov cx, 34
s:mov es:[bx], dl
add bx, 2
loop s
ret
code ends
end start
实验结果:



浙公网安备 33010602011771号