编程语言
首页 > 编程语言> > 实验3 转移指令跳转原理及其简单应用编程

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

作者:互联网

------------恢复内容开始------------

1. 实验任务1
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

 

 

 根据机器码可知偏移的位移量的补码为F2H,用十进制数表示为-14,所以偏移量为14;根据操作码所占用的空间,在loop s1后一条指令到标号s1之间,机器码一共占用了14个字节的空间。

 

 根据结果可知:位移量的补码为F0,转换成10进制为-16,所以偏移量为16,在loop s2后一条指令到标号s2之间,机器码一共占用了16个字节的空间。

2. 实验任务2 
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 word指令 时会将他的下一条指令的偏移地址(当前的ip)压入栈中,所以第一次使用的时候,0021进入栈中,第二次call指令为call dword 是将cs:ip地址方便进入栈中,其中先进段地址,再存偏移地址。所以ax=0021 ,bx=0026,cx=076c

   答:一致

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 si, offset x
    mov cx, len
    mov bl,0ah
 s1:
     mov al, [si]
     mov ah,0;必须填补一个0,被除数必需在16位
    call printNumber

    inc si
    call printSpace
    
    loop s1

     mov ah, 4ch
    int 21h
    printSpace proc
    mov ah, 2
         mov dl, ' '
         int 21h
      ret

    printSpace endp
    printNumber proc
 
      div bl;除数8位
      mov dl,al;al存储商
      or dl,30h;
      mov dh,ah
      or dh,30h
      mov ah, 2
      mov dl,dl
      int 21h
      mov dl,dh
      int 21h
      ret
    printNumber endp

code ends
end start

  运行测试截图:

4. 实验任务4
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 ;B8000H~BFFFFH空间共32KB的空间为80*25彩色字符模式的显示缓冲区
        mov es, ax

        mov si, offset str;偏移地址—》si
        mov cx, len;
        mov bl, 2h ;颜色为绿色,
        mov bh, 0 ;行数为第0行
        call printStr

        mov si, offset str
        mov cx, len
        mov bl, 4h ;颜色为红色
        mov bh, 24 ;行数为第24行
        call printStr

        mov ax, 4c00h
        int 21h

printStr:
        mov al, 160 ;每一行字符占用空间: 高位存放着字符的ascll码,低位存放着属性
        mul bh ;8 位操作数与 AL 寄存器的乘法;
        mov di, ax ;ax为第bh行的偏移量
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

 

5. 实验任务5
assume ds:data, cs:code

data segment
    str db '201983290280'
    len equ $ - str
data ends

code segment
start:
        mov ax, data
        mov ds, ax
        mov ax, 0b800h
        mov es, ax
        mov cx, 4000 ;每一屏的内容在显示缓冲区所占字节数:80×25×2 = 4000Bytes
        mov di, 0
        mov ah,17h ;蓝底白字     00010111
 s1:    mov al, 0
        mov es:[di], al
        mov es:[di+1], ah
        add di, 2
        loop s1
        ;最后一行开始的-
        mov di, 3840 ;第24行开始
        call printSign;
        ;打印学号
        mov di, 3908 ;3840+68
        mov si, offset str
        mov cx, len
        mov ah, 17h
s2:    call printstr
        inc si
        add di, 2
        loop s2

        ;最后一行最后的-
        mov di, 3932 ;=3840-68
        call printSign
        mov ax, 4c00h
        int 21h

printstr:
        mov al, [si]
        mov es:[di], al
        mov es:[di+1], ah
        ret
printSign:
        mov cx, 34
        mov ah, 17h
      s :mov al, 2Dh ;-
        mov es:[di], al
        mov es:[di + 1], ah
        add di,2
        loop s
        ret

code ends
end start

 

 

 

标签:di,ah,编程,mov,si,指令,跳转,ax,data
来源: https://www.cnblogs.com/DerekRay/p/15597923.html