zoukankan      html  css  js  c++  java
  • 实验3 转移指令跳转原理及其简单应用编程

    一、实验目的

    1. 理解和掌握转移指令的跳转原理
    2. 掌握使用call和ret指令实现子程序的方法,理解和掌握其参数传递方式
    3. 理解和掌握80×25彩色字符模式显示原理
    4. 综合应用寻址方式和汇编指令完成简单应用编程

    二、实验准备

    复习教材9-10章:

    • 转移指令的跳转原理
    • 汇编指令jmp, loop, jcxz, call, ret, retf的用法

    三、实验内容

    1. 实验任务1


    实验的源码以及编译运行结果

    • task1源码
      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
      
    • 编译连接的结果
      image

    image

    • 问题1

      loop s1反汇编跳转的位移是F2,-14,F2是14的补码

      cpu读取了loop指令之后IP变成001B,需要跳转到000D,所以偏移量为-14

      image

    • 问题2

      loop s2指令的跳转偏移地址是-16,F0(补码)

      IP读取完loop指令之后,偏移地址为0039H,跳转的偏移地址是0029H,所以偏移量为-16

      image


    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 star
      
    • 给出分析、调试、验证后,寄存器(ax) = ? (bx) = ? (cx) = ? 附上调试结果界面截图。

      编译结果

      image

      1.ax寄存器的值为21H,bx寄存器的值为26H,cx寄存器的值为076C

      call指令会将ip的地址入栈,所以出栈的是ip的存入地址,给ax

      call dword会将cs:ip分别入栈,所以分别出栈赋给了cx,bx;

      2和分析结果一致

    image


    3.实验任务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
      	
      	mov cx,len
      	mov si,0
      s:  mov ah,0
      	mov al,[si]
      	mov bx,offset printnumber
      	call bx#调用打印函数
      	mov bx,offset printSpace
      	call bx#打印空格
      	inc si
      	loop s
      	 
      	mov ah, 4ch
          int 21h
      
      printnumber:
      	mov bl,10#分离个位数和十位数
      	div bl
      	
      	mov bx,ax
      	mov ah,2
      	
      	mov dl,bl#打印商
      	or dl,30h#转成字符
      	int 21h
      	
      	mov dl,bh#打印余数
      	or dl,30h#转成字符
      	int 21h
      	ret
      printSpace:
      	mov ah,2
      	mov dl,' '
      	int 21h
      	ret
      code ends
      end start
      
    • 运行测试截图

    image


    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 ax,0B800H
      	mov es,ax
      	
      	mov si,offset printStr#第一次打印
      	mov ah,2#属性颜色
      	mov bx,0#位移到第一行
      	call si
      	
      	mov si,offset printStr#第二次打印
      	mov ah,4
      	mov bx,0F00H#最后一行
      	call si
      	
      	mov ah, 4ch
          int 21h
      
      printStr:
      	mov cx,len#打印三个字符
      	mov si,0
      s:  mov al,[si]
      	mov es:[bx+si],ax
      	inc si
      	inc bx
      	loop s
      	ret
      
      code ends
      end start
      
    • 运行测试截图

    image



    5.实验任务5

    • task5.asm源码
      assume cs:code, ds:data
      
      data segment
      	stu_no db '201983290498' 
      	len = $ - stu_no
      data ends
      
      code segment
      start:  
          mov ax, data
          mov ds, ax
      	mov ax,0B800H
      	mov es,ax
      
      	mov cx,0780H;将除了最后一行的染成蓝色
      	mov ah,10H
      	mov al,' '
      	mov bx,0
      s:  mov es:[bx],ax
      	add bx,2
      	loop s
      	
      	mov cx,80;打印最后一行横线
      	mov ah,17H
      	mov al,'-'
      s1: mov es:[bx],ax
      	add bx,2
      	loop s1
      
      	mov cx,len;打印学号
      	mov bx,0F44H
      	mov si,0
      s2: mov al,[si]
      	mov es:[bx],ax
      	inc si
      	add bx,2
      	loop s2
      
      	mov ah, 4ch
          int 21h
      
      code ends
      end start
      
    • 运行测试截图

    image

  • 相关阅读:
    哈工大中文篇章关系语料
    MongoDB学习笔记~关于官方驱动集成IQueryable之后的一些事
    MongoDB学习笔记~为IMongoRepository接口更新指定字段
    MongoDB学习笔记系列
    MongoDB学习笔记~为IMongoRepository接口添加了增删改方法,针对官方驱动
    MongoDB学习笔记~为IMongoRepository接口添加了排序和表达式树,针对官方驱动
    Android NDK入门实例 计算斐波那契数列二生成.so库文件
    Spring Autowire自动装配
    在gem5的full system下运行 alpha编译的测试程序 running gem5 on ubuntu in full system mode in alpha
    工厂三兄弟之抽象工厂模式(二)
  • 原文地址:https://www.cnblogs.com/hjw201983290498/p/15594769.html
Copyright © 2011-2022 走看看