任务一
- 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指令,能否替换成如下代码?你的结论的依据/理由是什么?
add si, 2
add di, 2
不能,inc不该变标志位CF,而add改变
- 在debug中调试,观察数据段中做128位加之前和加之后,数据段的值的变化。给出调试观察截图。
执行前
执行后为4230h 7750h f588h a188h bb5ah 62c8h 9649h a943h
任务二
- 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
- 运行测试截图
- 回答问题
运行程序,从键盘上输入一串字符,以#结束(比如,输入George Orwell, 1984#),观察结果。结合运行结果,理解代码并回答问题:
① 汇编指令代码line11-18,实现的功能是?
输入的字符按顺序复制到ds:[si]中,遇到#跳出循环
② 汇编指令代码line20-22,实现的功能是?
OAH功能是换行
③ 汇编指令代码line24-30,实现的功能是?
在屏幕上显示
任务三
- task3.asm
assume cs:code,ds:data
data segment
x dw 91, 792, 8536, 65521, 2021
len equ $ - x
data ends
stack segment
dw 32 dup(?)
stack ends
code segment
start:
mov ax,data
mov ds,ax
mov si,offset x
mov cx ,len/2
mov sp,64
mov ss,ax
mov ax,stack
s: mov ax,ds:[si]
inc si
inc si
push cx
call printNumber
call printSpace
pop cx
loop s
mov ah,4ch
int 21h
printNumber:
mov bx,0
L0: mov di, 10
mov dx, 0
div di
push dx
inc bx
cmp ax, 0
jne L0
mov cx,bx
L1: pop dx
add dl, 48
mov ah, 2
int 21h
loop L1
ret
printSpace:
mov ah, 2
mov dl,' '
int 21h
ret
code ends
end start
- 运行测试
任务四
- task4.asm
assume cs:code,ds:data
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,offset str
mov cx,len
s: call strupr
mov ax,4ch
int 21h
strupr:
s1: mov al,[si]
cmp al,'a'
jb s2
cmp al,'z'
ja s2
sub byte ptr [si],32
s2: inc si
loop s1
ret
code ends
end start
- 在debug中调试截图
任务五
- 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 ; 设置光标位置在第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显示yes,其他的显示no
任务六
- task6_1
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
string db "welcome to 2049!"
len equ $ - string
; 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
- task6_2
assume cs:code
code segment
start:
int 42
mov ah, 4ch
int 21h
code ends
end start
-
运行测试
-
通过此项实现任务,你对中断、软中断机制的理解
中断是指在事情处理的先后顺序上进行操作。产生中断时,根据CS:IP指向的入口处理中断程序,完成后返回