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指令执行后从001B跳转到标号s1其后指令地址为000D,位移量为-14
CPU根据s1的大小和loop s1指令的位置进行计算得到
② line44,汇编指令 loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明 是如何计算得到跳转后标号s2其后指令的偏移地址的。
loop s2指令执行后从0039跳转到标号s1其后指令地址为0029,位移量为-16
CPU根据s2的大小和loop s2指令的位置进行计算得到
③ 附上上述分析时,在debug中进行调试观察的反汇编截图
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
① 根据call指令的跳转原理,先从理论上分析,程序执行到退出(line31)之前,寄存器(ax) = ? 寄存器 (bx) = ? 寄存器(cx) = ?
ax=s1的偏移地址
bx=s2的偏移地址
cx=s3的偏移地址
根据反汇编结果应该为
ax=0021 bx=0026 cx=076c
② 对源程序进行汇编、链接,得到可执行程序task2.exe。使用debug调试,观察、验证调试结果与理论 分析结果是否一致。
3. 实验任务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 s:mov ax,0 mov al,[si] call printNumber call printSpace inc si loop s mov ah, 4ch int 21h printNumber: mov dl,10 div dl mov bx,ax mov ah, 2 mov dl, bl or dl, 30h int 21h mov ah, 2 mov dl, bh or dl, 30h int 21h ret printSpace: mov dl, ' ' int 21h ret code ends end start
4. 实验任务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 cx, len mov bh,0 mov bl, 2 call printStr mov si, offset str mov cx, len mov bh,24 mov bl, 5 call printStr mov ah, 4ch int 21h printStr: mov ax,0b800h mov es,ax mov al,bh mov dl,160 mul dl mov di,ax s:mov al,ds:[si] mov ah,bl mov es:[di],ax add di,2 inc si loop s ret code ends end start
5. 实验任务5
assume cs:code, ds:data data segment stu_no db '201983290093' len = $ - stu_no data ends code segment start: mov ax, data mov ds, ax mov si, offset stu_no mov al,24 mov bl,80 mul bl mov cx,ax ;设置cx mov ax,0b800h mov es,ax mov di,0 mov ah,16 mov al," " blue:mov es:[di],ax add di,2 loop blue mov cx,34 mov ah,23 mov al,"-" x:mov es:[di],ax add di,2 loop x mov cx,len mov ah,23 s:mov al,ds:[si] mov es:[di],ax add di,2 inc si loop s mov cx,34 mov ah,23 mov al,"-" x1:mov es:[di],ax add di,2 loop x1 mov ah, 4ch int 21h code ends end start