zoukankan      html  css  js  c++  java
  • 汇编实验4

    实验4 8086标志寄存器及中断

    1. 实验任务1

    • task1.asm源码

      assume cs:code, ds:data
      
      data segment
         x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h
         y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912h
      data ends
      code segment 
      start:
          mov ax, data
          mov ds, ax
          mov si, offset x
          mov di, offset y
          call add128
      
          mov ah, 4ch
          int 21h
      
      add128:
          push ax
          push cx
          push si
          push di
      
          sub ax, ax
      
          mov cx, 8
      s:  mov ax, [si]
          adc ax, [di]
          mov [si], ax
      
          inc si
          inc si
          inc di
          inc di
          loop s
      
          pop di
          pop si
          pop cx
          pop ax
          ret
      code ends
      end start
      
      • 回答问题
        line31~line34的4条inc指令,能否替换成如下代码?你的结论的依据/理由是什么?

      这个汇编语言的目的是事先一个超长的数的相加,因此低位的数对高位的进位不能被影响,就是CF标志位不能被影响。inc指令影响标志位OF,SF,ZF,PF 和AF,不影响CF。所以不能替换。

      • 在debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截

        可以发现截图的结果是定义的两行数据之和。

      2. 实验任务2

      此部分书写内容:

      • 程序task2.asm源码
    点击查看代码
      assume cs:code, ds:data
      data segment
              str db 80 dup(?)
      data ends
    
      code segment
      start:  
              mov ax, data
              mov ds, ax
              mov si, 0
      s1:        
              mov ah, 1
              int 21h;读入字符指令
              mov [si], al
              cmp al, '#'
              je next;当遇到#号时,跳出输入
              inc si;字符的长度
              jmp s1
      next:
              mov ah, 2;以字符的形式输出
              mov dl, 0ah
              int 21h
              
              mov cx, si
              mov si, 0
      s2:     mov ah, 2
              mov dl, [si]
              int 21h;打印输入的字符
              inc si
              loop s2
    
              mov ah, 4ch
              int 21h
      code ends
      end start
    
    • 运行测试截图

    • 回答问题

    汇编指令代码汇编指令代码line11-18,实现的功能是从屏幕读取数据
    汇编指令代码line20-22,实现的功能是打印换行键
    汇编指令代码line24-30,实现的功能是将输入的字符打印出来


    实验任务3

    此部分书写内容:

    • task3.asm源码
    点击查看代码
    DATAS SEGMENT
    	x dw 91, 792, 8536, 65521, 2021
    	len equ $ - x
    DATAS ENDS
    
    CODES SEGMENT
        ASSUME CS:CODES,DS:DATAS
    START:
    	mov ax,DATAS
    	mov ds,ax
    	mov dl,48
    	mov dx,0
    	mov bx,10
    	mov cx,len/2
    	mov si,0
      s:mov ax,ds:[si]
        mov di,0
    	call pn
    	call ps
    	add si,2
    	loop s
    
        MOV AH,4CH
        INT 21H
    
     pn:cmp ax,0
        je ot1
        div bx
        push dx
        mov dx,0
        inc di
        jmp pn
    
    ot1:cmp di,0
        jne sh
        ret
    
     sh:pop ax
        mov ah,2
        add al,48
     	mov dl,al
        int 21h
        dec di
        jmp ot1
    
     ps:mov ah,2
    	mov dl,0
    	int 21h
        ret
    CODES ENDS
        END START
    

    image

    4. 实验任务4

    此部分书写内容:

    • task4.asm源码
    点击查看代码
    assume cs:code, ds:data
    
    data segment
       strr db "assembly language, it's not difficult but tedious"
       len equ $ - strr
    data ends
    code segment 
    start:
        mov ax, data
        mov ds, ax
    	mov si,0
    	
    	mov cx,len
    s:  mov al,[si]
    	cmp al,'a'
    	jb s2
    	cmp al,'z'
    	ja s2
    	and al,11011111B
    	mov [si],al
    	
    s2:	inc si
    	loop s
        mov ah, 4ch
        int 21h
    
    
    code ends
    end start
    end start
    
    • 结果
      image

    实验任务5

    此部分书写内容

    • task5.asm源码
    点击查看代码
    assume cs:code, ds:data
    
    data segment
        str1 db "yes", '$'
        str2 db "no", '$'
    data ends
    
    code segment
    start:
        mov ax, data
        mov ds, ax
    
        mov ah, 1
        int 21h
    
        mov ah, 2;设置光标位置
        mov bh, 0;显示页码
        mov dh, 24;行(Y坐标)
        mov dl, 70;列(X坐标)
        int 10h;10H中断是由BIOS对显示器和屏幕所提供的服务程序,和ah结合使用
    
        cmp al, '7'
        je s1
        mov ah, 9
        mov dx, offset str2
        int 21h
    
        jmp over
    
    s1: mov ah, 9
        mov dx, offset str1;(ds:dx) = 字符串的首地址的段地址和偏移地址
        int 21h;DOS系统功能调用int 21h的9号子功能
    over:  
        mov ah, 4ch
        int 21h
    code ends
    end start
    
    - 运行成果的截图

    image

    • 程序的功能是:判读输入 的字符是否为7.

    实验任务6

    此部分书写内容:

    • 通过此项实现任务,你对中断、软中断实现机制的理解

    软中断就是调用一些系统函数,只需要在相应的寄存器上输入参数,然后进行软中断,调用系统函数,例如打印等。中断原本的程序

  • 相关阅读:
    lamp
    mysql多实例部署
    mysql进阶
    rsync
    mysql基础
    httpd
    ftp
    高级命令之awk
    NFS
    网络进阶管理
  • 原文地址:https://www.cnblogs.com/hjw201983290498/p/15659254.html
Copyright © 2011-2022 走看看