汇编语言程序设计实验三:转移指令跳转原理及其简单应用编程
实验任务一
-
task1.asm源码:
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 -
运行结果截图:
![]()
![]()
-
问题①
-
debug反汇编截图:
![]()
-
跳转位移量:执行完LOOP 000D指令后,IP自动加2,变为001B,然后进行跳转;故Loop指令结束地址为:001B,由于s1指令开始地址为000D,001B-000D=14,故跳转位移量为14。
-
-
问题②
-
继续进行反汇编,截图如下:
![]()
-
跳转位移量:Loop指令结束地址为0039,s1指令开始地址为0029,故跳转位移量为001B-000D=16
-
实验任务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)应该为s1的偏移地址,寄存器(bx)应该为s2的偏移地址,寄存器(cx)应该为cs的段地址。
-
对源程序进行汇编、链接,得到可执行程序task2.exe。使用debug调试,观察、验证调试结果与理论分析结果一致,汇编链接截图如下:
![]()
调试结果截图如下:
![]()
由图可知:- 执行完call word ptr ds:[0]后IP=0021,执行完POP AX后被压入栈中(AX=0021),此时IP=0027正好是s1的偏移地址。
- 执行完call word ptr ds:[2]后s2:POP BX的CS及下一条指令IP值先后压入栈中(BX=0026,CX=076C),此时IP=0028正好是s2的偏移地址。
实验任务三
- task3.asm代码如下:
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, 0 mov bl, 10 mov cx, len s: mov ah, 0 mov al, [si] call printNumber call printSpace inc si loop s mov ah, 4ch int 21h printNumber: div bl mov dl, al ;商 mov bh, ah ;余数 or dl,30H ;十位输出 mov ah,2 int 21h mov dl, bh ;个位输出 or dl,30H mov ah,2 int 21h ret printSpace: mov ah, 2 mov dl, ' ' int 21h ret code ends end start - 运行测试截图如下:
![]()
![]()
实验任务四
-
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,offset str mov cx,len mov bl,00000010b mov bh,1 call printStr mov si,offset str mov cx,len mov bl,00000100b mov bh,23 call printStr mov ah,4ch int 21h printStr: mov ax,0b800h mov es,ax mov ax,0 mov al,bh mov dx,0a0h mul dx mov di,ax s: mov ah,ds:[si] mov es:[di],ah mov es:[di+1],bl add di,2 inc si loop s ret code ends end start -
运行测试截图如下:
![]()
![]()
实验任务五
-
task5.asm代码如下:
assume cs:code, ds:data data segment stu_no db '201983290448' 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 s1:mov es:[si], dl add si, 2 loop s1 mov dh, 24 ; mov al, 160 mul dh mov bx, ax call minus mov si, 0 mov cx, len s2:mov dl, [si] mov es:[bx], dl add bx, 2 inc si loop s2 call minus mov ax, 4c00h int 21h minus: mov dl, '-' mov cx, 34 s3:mov es:[bx], dl add bx, 2 loop s3 ret code ends end start -
运行测试截图如下:
![]()
![]()
实验总结
- OFFSET 运算符返回数据标号的偏移量。这个偏移量按字节计算,表示的是该数据标号距离数据段起始地址的距离。
- 实验时需细心,并在实践中不断巩固基础知识,增强实践能力













浙公网安备 33010602011771号