实验3 转移指令跳转原理及其简单应用编程
1. 实验任务1
此部分书写内容:
给出程序task1.asm源码,及,运行截图
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

回答问题①
① line27, 汇编指令loop s1跳转时,是根据位移量跳转的。通过debug反汇编,查看其机器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明是如何计算得到跳转后标号s1其后指令的偏移地址的。
图中可知loop s1的机器码为 E2F2,已知loop跳转指令为短距离跳转,跳转范围-128~127,故对应两位机器码F2,由于往低地址跳转,故跳转的位移量为F2的补码,即十进制14字节。
回答问题②
② line44,汇编指令loop s2跳转时,是根据位移量跳转的。通过debug反汇编,查看其机器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明是如何计算得到跳转后标号s2其后指令的偏移地址的。
由图可知,机器码为E2F0,F0即为跳转的位移量的补码,进行求补后得出10010000,十进制数对应-16,因此跳转的位移量是-16。
从CPU的角度,当cx不为0时,(IP)=(IP)+8位位移,而此时IP地址更新为Loop指令的后一条指令的地址0039。因此位移量为-16时,从0039跳转到0029。
问题③
③附上上述分析时,在debug中进行调试观察的反汇编截图
1、2已放入
2. 实验任务2
此部分书写内容:
给出程序task2.asm源码
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) = ? (bx) = ? (cx) = ? 附上调试结果界面截图。
①根据call指令的跳转原理,先从理论上分析,程序执行到退出(line31)之前,寄存器(ax) =? 寄存器(bx) = ? 寄存器(cx) = ?
程序退出之前,ax存的数据为offset s1,bx存的数据为offset s2,cx存的数据为cs
②对源程序进行汇编、链接,得到可执行程序task2.exe。使用debug调试,观察、验证调试结果与理论分析结果是否一致。

ax=0021 bx=0026 cx=076C,结论正确
3. 实验任务3
此部分书写内容:
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
给出程序源码task3.asm运行测试截图
4. 实验任务4
此部分书写内容:
assume cs:code, ds:data data segment str db 'try' len = $-str data ends stack segment db 16 dup(0) stack ends code segment start: mov ax,data mov ds,ax mov ax,stack mov ss,ax mov sp,16 mov si,offset str mov cx,len mov bl,2;绿色 mov bh,0 call printStr mov si,offset str mov cx,len mov bl,4 mov bh,24 call printStr mov ah,4ch int 21h printStr: mov dx,0b800h mov es,dx mov ah,0 mov al,bh mov di,160 mul di mov di,ax s: mov al,ds:[si] mov es:[di],al inc di mov es:[di],bl inc di inc si loop s ret code ends end start
给出程序源码task4.asm运行测试截图
5. 实验任务5
此部分书写内容:
assume ds:data, cs:code data segment stu_no db '201983300980' len = $ - stu_no data ends code segment start: mov ax, data mov ds, ax mov cx, 4000 mov si, offset stu_no mov ax, 0b800h mov es, ax mov di, 0 mov ah,17h s: mov al, 0 mov es:[di], al mov es:[di+1], ah inc si add di, 2 loop s mov di, 3840 mov si, offset stu_no mov cx, 74 mov ah, 17h s1: call printgang add di, 2 loop s1 mov di, 3908 mov si, offset stu_no mov cx, len mov ah, 17h s2: call printStu_no inc si add di, 2 loop s2 mov di, 3932 mov si, offset stu_no mov cx, 74 mov ah, 17h s3: call printgang add di, 2 loop s3 mov ax, 4c00h int 21h printStu_no:mov al, [si] mov es:[di], al mov es:[di+1], ah ret printgang:mov al, 45 mov es:[di], al mov es:[di + 1], ah ret code ends end start
给出程序源码task5.asm运行测试截图

浙公网安备 33010602011771号