实验3 转移指令跳转原理及其简单应用编程

实验3 转移指令跳转原理及其简单应用编程

实验任务1

  • 给出程序task1.asm源码及运行截图

    • 源码:

      assume cs:code, ds:data
      data segment
      	x db 1, 9, 3
      	len1 equ $ - x ; 符号常量, $指下一个数据项的偏移地址,这个示例中,是3
      	y dw 1, 9, 3
      	len2 equ $ - y ; 符号常量, $指下一个数据项的偏移地址,这个示例中,是9
      data ends
      code segment
      start:
      	mov ax, data
      	mov ds, ax
      	mov si, offset x ; 取符号x对应的偏移地址0 -> si
      	mov cx, len1 ; 从符号x开始的连续字节数据项个数 -> cx
      	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 ; 取符号y对应的偏移地址3 -> si
      	mov cx, len2/2 ; 从符号y开始的连续字数据项个数 -> cx
      	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
      
    • 运行截图:

    image-20211202203340506

  • line27, 汇编指令loop s1 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明是如何计算得到跳转后标号s1其后指令的偏移地址的。

    image-20211202215126377

  • line44,汇编指令loop s2 跳转时,是根据位移量跳转的。通过debug反汇编,查看其机器码,分析其跳转的位移量是多少?(位移量数值以十进制数值回答)从CPU的角度,说明是如何计算得到跳转后标号s2其后指令的偏移地址的。

    image-20211202215717744

实验任务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=21h,bx=26h,cx=76ch

  • 对源程序进行汇编、链接,得到可执行程序task2.exe。使用debug调试,观察、验证调试结果与理论分析结果是否一致。

    image-20211202232013968

    image-20211202232127813

实验任务3

  • 给出程序源码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              ;将数据段的中的内容存在ds中作为段地址使用
    
        mov cx, len
        mov si, offset x
    
    s:  mov ah, 0
        mov al, ds:[si]
        call printNumber        ;call指令跳转,调用函数,打印数字
        call printSpace         ;call指令跳转,调用函数,打印空格
        inc si                  ;自动加一
        loop s                  ;循环打印出数字与空格
    
        mov ah, 4ch
        int 21h
    
    printNumber:                ;输出数字(通过除法,一个字符一个字符进行打印)
        mov bl, 10              ;10充当除数,传入的ax为被除数
        div bl
        mov dl, al
    
        mov dh, ah
    
        or dl, 30H              ;数值转字符
        mov ah, 2
        int 21h                 ;输出高位
    
        mov dl, dh
        or dl, 30H              ;数值转字符
        int 21h                 ;输出低位
    ret
    
    printSpace:                 ;输出空格
        mov dl, ' '
        int 21h        
    ret
    
    code ends
    end start
    
  • 运行测试截图

    image-20211202235623753

实验任务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              ;将数据段的中的内容存在ds中作为段地址使用
    
        mov si, offset str
        mov cx, len             ;设置循环次数
        mov bl, 00000010B       ;1(b)2(g)3(r)-前景色,4-高光,5(b)6(g)7(r)-背景色,8-闪烁
        mov bp, 00              ;第一行
    
        mov ax, 0B800H          ;80*25彩色字符显示区域的段地址
        mov es, ax
    
    s1: call printStr
        loop s1
    
        mov si,offset str
        mov cx,len              ;设置循环次数
        mov bl,00000100B        ;黑底红色
        mov bp,0F00H            ;最后一行
    
    s2: call printStr
        loop s2
    
        mov ah, 4ch
        int 21h
    
    
    printStr:
        mov ax, ds:[si]         ;取字母暂存于ax中
        mov es:[bp],ax          ;es:[bp]确定了要显示的位置
        inc bp
        inc si
        mov es:[bp],bl          ;确定要显示的颜色
        inc bp
    ret
    
    code ends
    end start
    
  • 运行测试截图

    image-20211203002534131

实验任务5

  • 给出程序源码task5.asm

    assume cs:code, ds:data
    
    data segment
        stu_no db '201913900042'
        len = $ - stu_no
    data ends
    
    code segment
    start:
        mov ax, data
        mov ds, ax
    
        mov si, offset stu_no
    
        mov cx, 2000
    
        mov bl, 00010000B
        mov ax, 0B800H
        mov es, ax
        mov bp, 00
    
    s1: inc bp
        mov es:[bp], bl
        inc bp
        loop s1                 ;界面设置为蓝色
    
        mov bp, 0F00H
        mov bl, 00010a111B       ;字体设置为白色
        mov cx, 80
    
    s2: mov ax, 45              ;横线/减号的ASCII码为45
        mov es:[bp], ax
        inc bp
        mov es:[bp], bl
        inc bp
        loop s2
    
        mov ax, data
        mov ds, ax
        mov si, offset stu_no
        mov bp, 0F44H
        mov cx, len
    
    s3: mov ax, ds:[si]
        mov es:[bp], ax
        inc si
        inc bp
        mov es:[bp], bl
        inc bp
        loop s3
    
    code ends
    end start
    
  • 运行测试截图

image-20211203003251141

posted @ 2021-12-03 00:37  韩金玲  阅读(15)  评论(2编辑  收藏  举报