1、实验任务1
task1.asm源码:
1 assume cs:code, ds:data 2 3 data segment 4 x db 1, 9, 3 5 len1 equ $ - x 6 7 y dw 1, 9, 3 8 len2 equ $ - y 9 data ends 10 11 code segment 12 start: 13 mov ax, data 14 mov ds, ax 15 16 mov si, offset x 17 mov cx, len1 18 mov ah, 2 19 s1:mov dl, [si] 20 or dl, 30h 21 int 21h 22 23 mov dl, ' ' 24 int 21h 25 26 inc si 27 loop s1 28 29 mov ah, 2 30 mov dl, 0ah 31 int 21h 32 33 mov si, offset y 34 mov cx, len2/2 35 mov ah, 2 36 s2:mov dx, [si] 37 or dl, 30h 38 int 21h 39 40 mov dl, ' ' 41 int 21h 42 43 add si, 2 44 loop s2 45 46 mov ah, 4ch 47 int 21h 48 code ends 49 end start
- 问题一、line27, 汇编指令 loop s1 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)
从CPU的角度,说明 是如何计算得到跳转后标号s1其后指令的偏移地址的。
答:通过反汇编可以得到跳转的位移量为-14(反汇编得到为F2,F2为-14的补码),因为执行loop指令后,IP先加一再进行跳转。
- 问题二、line44,汇编指令 loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机 器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回
答)从CPU的角度,说明 是如何计算得到跳转后标号s2其后指令的偏移地址的。
答:跳转的位移量为-16,原理与问题一相同。
2、实验任务2
task2.asm源码:
1 assume cs:code, ds:data 2 3 data segment 4 dw 200h, 0h, 230h, 0h 5 data ends 6 7 stack segment 8 db 16 dup(0) 9 stack ends 10 11 code segment 12 start: 13 mov ax, data 14 mov ds, ax 15 16 mov word ptr ds:[0], offset s1 17 mov word ptr ds:[2], offset s2 18 mov ds:[4], cs 19 20 mov ax, stack 21 mov ss, ax 22 mov sp, 16 23 24 call word ptr ds:[0] 25 s1: pop ax 26 27 call dword ptr ds:[2] 28 s2: pop bx 29 pop cx 30 31 mov ah, 4ch 32 int 21h 33 code ends 34 end start
- 问题一、根据call指令的跳转原理,先从理论上分析,程序执行到退出(line31)之前,寄存器(ax) = ? 寄存器(bx) = ? 寄存器(cx) = ?
答:(ax) = offset s1 (bx) = offset s2 (cx) = (cs)
- 问题二、对源程序进行汇编、链接,得到可执行程序task2.exe。使用debug调试,观察、验证调试结果与理论 分析结果是否一致。
与分析结果一致。
3、实验任务3
task3.asm源码:
1 assume cs:code, ds:data, ss:stack 2 3 data segment 4 x db 99, 72, 85, 63, 89, 97, 55 5 len equ $- x 6 db 0 7 data ends 8 9 stack segment 10 db 16 dup(0) 11 stack ends 12 13 code segment 14 start: 15 mov ax,data 16 mov ds,ax 17 18 mov ax,stack 19 mov ss,ax 20 mov sp,16 21 22 mov cx,len 23 mov bx,0 24 mov byte ptr ds:[len],10 25 26 s: mov ax,0 27 mov al,ds:[bx] 28 29 call printNumber 30 call printSpace 31 inc bx 32 loop s 33 34 mov ah,4ch 35 int 21h 36 37 printNumber: 38 push dx 39 div byte ptr ds:[len] 40 mov dx,ax 41 mov ah,2 42 add dl,30h 43 int 21h 44 45 mov dl,dh 46 mov ah,2 47 add dl,30h 48 int 21h 49 50 pop dx 51 ret 52 53 printSpace: 54 push dx 55 mov dl,' ' 56 mov ah,2 57 int 21h 58 59 pop dx 60 ret 61 62 code ends 63 end start
- 结果如下图所示:
4、实验任务4
task4.asm源码:
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,0 mov cx,len mov bl,2 mov bh,0 call printStr mov si,0 mov cx,len mov bl,4 mov bh,24 call printStr mov ah,4ch int 21h printStr: mov ax,0b800h mov es,ax mov ax,0 mov al,bh mov dx,160 mul dx mov di,ax s: mov al,ds:[si] mov es:[di],al inc si inc di mov es:[di],bl inc di loop s ret code ends end start
- 结果如下图所示:
5、实验任务5
task5.asm源码:
assume cs:code, ds:data data segment stu_no db '201983290132' len = $ - stu_no len1 = (80-len)/2 data ends code segment start: mov ax,data mov ds,ax mov bl,16 call printColor mov si,0 mov bl,23 mov bh,24 call printStr mov ah,4ch int 21h printColor: mov ax,0b800h mov es,ax mov ax,0 mov al,25 mov dx,0 mov dx,80 mul dx mov cx,ax mov al,' ' mov di,0 s: mov es:[di],al inc di mov es:[di],bl inc di loop s ret printStr: mov ax,0b800h mov es,ax mov ax,0 mov al,bh mov dx,160 mul dx mov di,ax mov al,'-' mov cx,len1 s1: mov es:[di],al inc di mov es:[di],bl inc di loop s1 mov cx,len s2: mov al,ds:[si] mov es:[di],al inc si inc di mov es:[di],bl inc di loop s2 mov al,'-' mov cx,len1 s3: mov es:[di],al inc di mov es:[di],bl inc di loop s3 ret code ends end start
- 结果如下图所示: