实验四

任务一

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

回答问题

1.不能,因为inc不会改变进位标志位CF,但是add可以改变进位标志位

2.

 

 

 

 

任务二

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

 

 

1.汇编指令代码 line11-18,实现的功能是?
判断输入字符是否等于 #,若不等于存入 data 段, 使用 si 计数,并继续读入;若等于则跳转至 next。

2.汇编指令代码 line20-22,实现的功能是?
ASCII 码中 0ah 为换行符,打印换行符使得输出字符串在下一行开始显示。

3.汇编指令代码 line24-30,实现的功能是?
将读入字符串长度写入 cx 使用 loop 循环输出字符串。

 

任务三

 

assume cs:code, ds:data

data segment
    x dw 91, 792, 8536, 65521, 2021
    len equ $ - x
data ends

code segment

; print number in ax (0 <= [ax] <= 65535) to console
; param     :  ax
; return    : none
printNumber:
    push bx
    push cx
    push dx

    mov cx, 0
s1: 
    mov dx, 0
    mov bx, 10
    div bx
    push dx
    inc cx
    cmp ax, 0
    jne s1

s2:
    pop dx
    add dx, 30h
    mov ah, 2
    int 21h
    loop s2

    pop dx
    pop cx
    pop bx
    ret

; print a space to console
; param     : none
; return    : none
printSpace:
    push ax
    push dx

    mov dl, 20h
    mov ah, 02h
    int 21h
    
    pop dx
    pop ax
    ret

main: 
    mov ax, data
    mov ds, ax

    mov cx, len
    mov di, offset x
s:  mov ax, [di]
    call printNumber
    call printSpace
    add di, 2
    sub cx, 1
    loop s

    mov ax, 4c00h
    int 21h

code ends

end main

 

 

 

 

 任务四

assume ds:data,cs:code
data segment
str db "assembly language, it's not difficult but tedious"
len equ $ - str
data ends
code segment
start:
mov ax,data
mov ds,ax
mov si,0
mov cx,len
call strupr
mov ax,4c00h
int 21h
strupr:
mov bl,11011111b
s1:
mov al,ds:[si]
cmp al,'a'
jb s2
cmp al,'z'
ja s2
and [si],bl

s2:
inc si
loop s1

ret

code ends
end start

 

 

 

 

 

 任务五

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 ; 设置光标位置在第24行
mov dl, 70 ; 设置光标位置在第70列
int 10h ; 设置光标位置
cmp al, '7'
je s1
mov ah, 9
mov dx, offset str2
int 21h ; 显示标号str2处的字符串
jmp over
s1: mov ah, 9
mov dx, offset str1
int 21h ; 显示标号str2处的字符串
over:
mov ah, 4ch
int 21h
code ends
end start

程序的功能是?
输入一个字符并判断输入的字符是否为 7,如果为7则在屏幕输出 yes 否则在屏幕输出 no;

 

任务六

程序的中断可分为内中断和外中断,本题实验为内中断,程序通过给出的中断类型码,在中断触发时运行的程序的地址为(N*4) : (N*4+2)号内存中存放的地址寻找新的执行程序,当程序遇到终端类型码,不再执行接下来的代码,而是执行终端代码,再执行完后会返回原位置。

assume cs:code

code segment
start:
    ; 42 interrupt routine install code
    mov ax, cs
    mov ds, ax
    mov si, offset int42  ; set ds:si

    mov ax, 0
    mov es, ax
    mov di, 200h        ; set es:di

    mov cx, offset int42_end - offset int42
    cld
    rep movsb

    ; set IVT(Interrupt Vector Table)
    mov ax, 0
    mov es, ax
    mov word ptr es:[42*4], 200h
    mov word ptr es:[42*4+2], 0

    mov ah, 4ch
    int 21h

int42:
    jmp short int42_start
    str db "welcome to 2049!"
    len equ $ - str

    ; display string "welcome to 2049!"
int42_start:
    mov ax, cs
    mov ds, ax
    mov si, 202h

    mov ax, 0b800h
    mov es, ax
    mov di, 24*160 + 32*2

    mov cx, len
s:  mov al, [si]
    mov es:[di], al
    mov byte ptr es:[di+1], 2
    inc si
    add di, 2
    loop s

    iret
int42_end:
   nop
code ends
end start
assume cs:code

code segment
start:
    int 42

    mov ah, 4ch
    int 21h
code ends
end start

通过 int 42软中断调用,在屏幕下方输出绿色字符串“welcome to 2049”

 

posted @ 2021-12-16 11:46  1171021785  阅读(50)  评论(3)    收藏  举报