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

 

 loop s1 指令对应的机器码为E2F2,

对F2(11110010)求补=10001110=-14,位移量为-14

偏移地址=该指令的下一条指令的地址+位移量

001B-000D=000D

000D为s1的偏移地址,验证成功。

 loop s1 指令对应的机器码为E2F0,

对F2(11110000)求补=10010000=-16,位移量为-16

偏移地址=该指令的下一条指令的地址+位移量

0039-0010=0029

0029为s2的偏移地址,验证成功。

 

 

cal word ptr ds:[0] 将s1的偏移地址压入栈中

pop ax 把s1的偏移地址出栈,ax=0021

call dword ptr ds:[2] 将s2的段地址和偏移地址分别压入栈中

pop bx,把s2的偏移地址出栈,bc=0026

pop cx,把s2的段地址出栈,cx=076C

 结果一致

 

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 di, 0
    mov cx,len
    mov byte ptr ds:[len] ,10

 s1:
    mov al,ds:[di]
    mov ah,0
    div byte ptr ds:[len]
    call printNumber
    call printSpace
    inc di
    loop s1
    mov ah ,4ch
    int 21h

    printNumber: 
        mov bx , ax
        or bl , 30h
        or bh , 30h
        mov dl , bl
        mov ah , 2
        int 21h
        mov dl , bh
        mov ah , 2
        int 21h
        ret

    printSpace:
        mov ah , 2
        mov dl , ' '
        int 21h
        ret

code ends
end start

运行结果:

         

 

 

 

商为al,余数为ah,把十六进制下的数值,拆分开来,al表示十位,ah表示个位,然后再转化为字符输出

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 cx,len
    mov si,0
    mov bl,2
    mov bh,10

    mov ax,0a0h
    mul bh
    mov bp,ax

 s1:
    call printStr
    loop s1
    mov ah ,4ch
    int 21h

printStr:
    mov al,ds:[si]
    mov es:[bp],al
    inc bp
    mov es:[bp],bl
    inc si
    inc bp
    ret

code ends
end start

运行结果:

         

 bl的颜色属性为 I R G B | I R G B

assume cs:code, ds:data 

data segment
    stu_no db '201983290196'
    len = $ - stu_no 
data ends 

code segment 
start:
    mov ax, data 
    mov ds, ax 
    mov bp, 0 
    mov ax, 0b800h
    mov es, ax 
    mov si, 1
    mov cx, 2080
s1:
    mov ah, 17h
    mov es:[si], ah
    add si, 2 
    loop s1
    mov si, 3840


    mov cx, 34
s2:
    mov al, '-'
    mov es:[si], al
    add si, 2
    loop s2 
    mov cx, 12 


    mov bp, 0 
s3:
    mov al, ds:[bp]
    mov es:[si], al
    add si, 2
    add bp, 1
    loop s3 
    

    mov cx, 34
s4:
    mov al, '-'
    mov es:[si], al
    add si, 2
    loop s4
    mov cx, 12 

    mov ax, 4c00h 
    int 21h 

code ends 
end start

 

 

posted @ 2021-11-29 12:47  melons  阅读(39)  评论(3编辑  收藏  举报