实验一:
源码:
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
运行截图:
问题一:
跳转的位移量:242字节
根据loop指令的机器码后两位F2可知,位移量为F2,再由loop指令后的第一个字节的地址001B加上F2可得下一条将要执行指令的IP地址。
问题二:
跳转的位移量:240字节
根据loop指令的机器码后两位F0可知,位移量为F0,再由loop指令后的第一个字节的地址0039加上F0可得下一条将要执行指令的IP地址。
问题三:
实验二:
源码:
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 = 标号s1的偏移地址
bx = 标号s2的偏移地址
cx = cs
分析:
程序运行到第24行时,先将当前IP值(即s1)入栈,然后转移到标号处(ds:[0])执行指令。当执行完第25行后,把IP值出栈,并存储在ax寄存器中,故(ax)=s1。
程序运行到第27行时,先将当前CS(段地址)和IP(s2)依次入栈,然后转移到标号处(ds:[2])执行指令。当执行完第29行后,先把IP值出栈,并存储在bx寄存器中,故(bx)=s2。再把CS值出栈,并存储在cx寄存器中,故(cx)=cs。
实验三:
源码:
assume cs:code data segment x db 99, 72, 85, 63, 89, 97, 55 len equ $ - x data ends code segment main: mov ax,data mov ds,ax mov si,offset x mov cx,len s: mov ah,0 call printNumber call printSpace loop s mov ax,4c00h int 21h printNumber: mov al,ds:[si] mov bl,10 div bl mov dl,al mov dh,ah mov ah,2 or dl,30h int 21h mov dl,dh or dl,30h int 21h inc si ret printSpace: mov ah,2 mov dl,' ' int 21h ret code ends end main
截图:
实验四:
源码:
assume cs:code data segment str db 'try' len equ $ - str data ends code segment start: mov ax,data mov ds,ax mov ax,0b800h mov es,ax mov si,0 mov bh,0 mov bl,71h call printStr mov si,0 mov bh,24 mov bl,60h call printStr mov ax,4c00h int 21h printStr: mov al,160 mul bh mov di,ax mov cx,len s:mov dl,ds:[si] mov es:[di],dl inc di mov es:[di],bl inc di inc si loop s ret code ends end start
截图:
实验五:
源码:
assume cs:code data segment stu_no db '201983290180' len = $ - stu_no data ends code segment start: mov ax,data mov ds,ax mov ax,0b800h mov es,ax call printAll mov bh,24 mov al,160 mul bh mov bx,ax call printL call printN call printL mov ax,4c00h int 21h printL: mov al,'-' mov dl,17h mov cx,34 s: mov es:[bx],al inc bx mov es:[bx],dl inc bx loop s ret printN: mov si,0 mov dl,17h mov cx,len s1: mov al,ds:[si] mov es:[bx],al inc bx mov es:[bx],dl inc bx inc si loop s1 ret printAll: mov si,1 mov bl,17h mov cx,7d0h s2: mov es:[si],bl add si,2 loop s2 ret code ends end start
截图: