start: mov ax,data mov ds,ax mov ax,x mov bx,y imul bx mov cx,ax mov bx,dx mov ax,z cwd add cx,ax adc bx,dx sub cx,0D0H 2.
Data segment grade dw 10 dup (90) Data ends Code segment
assume cs:code, ds:data start: mov ax,data mov ds,ax mov cx,50 mov bx,0 mov ax,0 again: 3. len equ 51 Data segment
string db len,?,len dup(?) lf db 0ah
Data ends Code segment
assume cs:code, ds:data
sbb bx,0 mov ax,v cwd sub ax,cx sbb dx,bx mov bx,x idiv bx mov sum1,ax mov sum2,dx mov ah,4ch int 21h Code ends
end start
add ax,grade[bx] inc bx inc bx loop again mov bx,50 div bx mov ah,4ch int 21h Code ends
end start start: mov ax,data mov ds,ax lea dx,string mov ah,0ah int 21h mov dl,lf
mov ah,2 int 21h mov cl,string[1] mov ch,0 lea bx,string[2] add bx,cx
mov byte ptr [bx],'$' lea dx,string[2]
四. 实验结果 1. x dw 21CH y dw 1H z dw 0FFFFH
mov ah,09h int 21h mov ah,4ch int 21h
end startCode ends
v dw 438H 结果为 sum1=0001 sum2=00d1 2.
输入10组数据,分别为90 输出 为46h 3.
输入:string 输出:string
五. 实验体会
掌握了顺序和循环程序结构和设计方法,以及字符、字符串的输入和显示,熟悉了在PC机上建立、汇编、连接、调试和运行8086/8088汇编语言程序的过程。
实验三 汇编语言子程序设计(分支、子程序)
一. 实验目的
1、掌握分支和子程序结构和设计方法;
2、熟悉在PC机上建立、汇编、连接、调试和运行8086/8088汇编语言程序的过程。 3、通过汇编语言了解高级语言的参数传递等知识。
二. 实验内容
1、1. BL中的只有一位为1。编写程序测试,并输出提示信息“The X Bit is 1”,要求:地址表和转移表。
2. 编写一个子程序计算z=f(x,y)=x*y+x-y(x,y,z有符号数内存数)。要求通过堆栈(寄存器、内存)传送所有参数。 三. 实验过程和程序 1.
地址表方法:
Data segment x db 10h
addrtbl dw l0,l1,l2,l3,l4,l5,l6,l7 s0 db 'The 0 Bit is 1.$' s1 db 'The 1 Bit is 1.$' s2 db 'The 2 Bit is 1.$' s3 db 'The 3 Bit is 1.$' s4 db 'The 4 Bit is 1.$' s5 db 'The 5 Bit is 1.$' s6 db 'The 6 Bit is 1.$' s7 db 'The 7 Bit is 1.$' Data ends Code segment
assume cs:code, ds:data start: mov ax,data mov ds,ax mov cx,8 mov bl,x again: shr bl,1 jnc l mov si,8
sub si,cx shl si,1 jmp addrtbl[si] l0: lea dx,s0 jmp output l1: lea dx,s1 jmp output l2: lea dx,s2 jmp output l3: lea dx,s3 jmp output l4: lea dx,s4 jmp output l5: lea dx,s5 jmp output l6: lea dx,s6
jmp output l7: lea dx,s7 jmp output l:
loop again output:
转移表方法:
Data segment x db 80h
addrtbl dw l0,l1,l2,l3,l4,l5,l6,l7 s0 db 'The 0 Bit is 1.$' s1 db 'The 1 Bit is 1.$' s2 db 'The 2 Bit is 1.$' s3 db 'The 3 Bit is 1.$' s4 db 'The 4 Bit is 1.$' s5 db 'The 5 Bit is 1.$' s6 db 'The 6 Bit is 1.$' s7 db 'The 7 Bit is 1.$' Data ends Code segment
assume cs:code, ds:data start: mov ax,data mov ds,ax mov cx,8 mov bl,x again: shr bl,1 jnc l mov si,8 sub si,cx l:
loop again lea ax,jmptbl
mov ah,9h int 21h mov ah,4ch int 21h Code ends
end start mov cx,si shl si,1 add si,cx add ax,si jmp ax jmptbl: jmp near ptr l0 jmp near ptr l1 jmp near ptr l2 jmp near ptr l3 jmp near ptr l4 jmp near ptr l5 jmp near ptr l6 jmp near ptr l7 l0: lea dx,s0 jmp output l1: lea dx,s1 jmp output l2: lea dx,s2 jmp output l3: lea dx,s3 jmp output l4: