当前位置:文档之家› 汇编语言实验整理

汇编语言实验整理

1.设计程序。

实现Y=2X+3,X是一位十进制数。

要求X从键盘输入,在下一行显示“Y=2X+3=”以及十进制计算结果。

data segment\x db?\y dw?\mess1db0ah,0dh,'input x:$'\mess2db 0ah,0dh,'Y=2X+3=$'\data ends\code segment\assume cs:code,ds:data\start:\mov ax,data\mov ds,ax\let3:\mov dx,offset mess1\mov ah,9\int21h\mov ah,1\int21h\cmp al,'0'\jb out1\ cmp al,'9'\ja out1\and al,0fh\mov bl,2\mul bl\add ax,3\mov y,ax\mov cx,0\mov bx,10\let0:\mov dx,0\inc cx\idiv bx\push dx\cmp ax,0\jne let0\mov dx,offset mess2\mov ah,9\int 21h\let1:\pop ax\add ax,0030h\mov dl,al\mov ah,2\int21h\ dec cx\cmp cx,0\jnz let1\jmp let3\out1:\mov ah,4ch\int21h\ code ends\end start2.编写程序,将键盘输入的小写字母变为大写字母显示在屏幕上,输入小写字母以外的其它字符则退出。

data segment\mess1db0ah,0dh,'xiaoxieinput:$'\mess2db 0ah,0dh,'daxieoutput:$'\data ends\code segment\assume cs:code,ds:data\start:\mov ax,data\mov ds,ax\let2:\mov dx,offset mess1\mov ah,9\int21h\mov ah,1\int21h\cmp al,'a'\jb out1\ cmp al,'z'\ja out1\mov bl,al\mov dx,offset mess2\mov ah,9\int 21h\let0:\sub bl,20h\mov dl,bl\mov ah,2\int21h\jmp let2\out1:\mov ah,4ch\int21h\code ends\end start3.设计程序。

实现Z=X/4+16*Y,X和Y都是一位十进制数。

要求从键盘输入,在下一行显示“Z=X/4+16*Y”以及十进制计算结果。

data segment\mess1db0ah,0dh,'input x:$'\mess2db0ah,0dh,'input y:$'\ mess3db0ah,0dh,'z=x/4+16*y=$'\data ends\code segment\assume cs:code,ds:data\start:\mov ax,data\mov ds,ax\let0:\mov dx,offset mess1\mov ah,9\int21h\mov ah,1\int21h\mov cl,2\sub al,30h\ mov ah,0\sar ax,cl\mov bl,al\mov dx,offset mess2\mov ah,9\int 21h\mov ah,1\int21h\sub al,30h\mov ah,0\mov cl,4\sal ax,cl\ add al,bl\mov bx,ax\mov dx,offset mess3\mov ah,9\int21h\let1:\ mov ax,bx\mov cx,0\mov bx,10\let2:\mov dx,0\inc cx\idiv bx\ push dx\cmp ax,0\jne let2\let3:\pop ax\add ax,0030h\mov dl,al\ mov ah,2\int21h\dec cx\cmp cx,0\jne let3\mov ah,4ch\int21h\code ends\end start4.用查表的方法将内存单元中的字用十六进制显示出来。

data segment\table db30h,31h,32h,33h,34h,35h,36h,37h\db 38h,39h,41h,42h,43h,44h,45h,46h\mess1db0ah,0dh,'output:$'\hex db 6\ascii db?\data ends\code segment\assume cs:code,ds:data\start:\ mov ax,data\mov ds,ax\mov dx,offset mess1\mov ah,9\int21h\mov bx,offset table\mov al,hex\xlat\mov ascii,al\mov dl,al\mov ah,2\int 21h\mov ah,4ch\int21h\code ends\end start5.输入0~255以内的十进制数,显示出相应的十六进制数。

data segment\x db3dup(?)\mess1db0dh,0ah,'decimal=$'\mess2db 0dh,0ah,'hex=$'\data ends\code segment\assume cs:code,ds:data\start:\mov ax,data\mov ds,ax\let0:\mov si,0\ mov x,0\mov x+1,0\mov x+2,0\mov dx,offset mess1\mov ah,9\int 21h\let1:\mov ah,1\int21h\cmp al,0dh\jz let2\sub al,30h\ mov x[si],al\inc si\jmp let1\let2:\mov dx,offset mess2\mov ah,9\ int21h\cmp si,1\ja let3\mov bl,x\mov cl,1\add bl,30h\mov dl,bl\mov ah,2\int21h\jmp out1\let3:\cmp si,2\ja let4\mov al,x\mov cl,10\mul cl\add al,x+1\mov ah,0\mov bl,16\div bl\ mov bx,ax\mov cl,2\jmp let5\let4:\mov al,x\mov cl,10\mul cl\ add al,x+1\mul cl\add al,x+2\mov ah,0\mov bl,16\div bl\mov bx,ax\mov cl,2\let5:\cmp bl,10\jl let6\add bl,7\let6:\add bl,30h\mov dl,bl\mov ah,2\int21h\mov bl,bh\dec cl\jne let5\out1:\mov ah,4ch\int21h\code ends\end start6.分支程序设计。

完成如下公式的计算,请写出程序。

(X+3)/2X>0Y=0X=0X×4X<0data segment\x dw-1200\y dw?,?\z dw10\count db0\data ends\code segment\assume ds:data,cs:code\start:\mov ax,data\mov ds,ax\cmp x,0\jg prog1\jz prog2\mov ah,2\ mov dl,2dh\int21h\mov ax,x\neg ax\mov cl,2\sal ax,cl\jmp exit\prog1:\mov ax,x\ add ax,3\mov bl,2\idiv bl\mov byte ptr y,al\mov byte ptr y+1,ah\mov ah,0\jmp exit\prog2:\mov y,0\mov ax,0\jmp exit\exit:mov dx,0\idiv z\ push dx\inc count\cmp ax,0\jnz exit\exit1:\ pop dx\add dx,0030h\mov ah,2\int21h\dec count\jnz exit1\mov ah,4ch\int21h\code ends\end start7.字数组M中有10个数据,分类统计其中正数、负数、0的个数,分别存入POSI、NEGA、ZERO单元。

data segment\M db91h,-1,2,3,4,5,80h,0,-3,-4\str1db'POSI:$'\str2db 0dh,0ah,'NEGA:$'\str3db0dh,0ah,'ZERO:$'\count1db0\count2db0\count3 db0\data ends\code segment\assume ds:data,cs:code\begin:\mov ax,data\mov ds,ax\mov si,0\for:\cmp si,10\ jz output\cmp M[si],0\jg for1\jl for2\inc count3\inc si\jmp for\for1:\inc count1\inc si\jmp for\for2:\inc count2\inc si\jmp for\output:\mov ah,9\mov dx,offset str1\int21h\ mov dl,count1\add dl,30h\mov ah,2\int21h\ mov ah,9\mov dx,offset str2\int21h\mov dl,count2\ add dl,30h\mov ah,2\int21h\mov ah,9\mov dx,offset str3\int21h\mov dl,count3\add dl,30h\ mov ah,2\int21h\mov ah,4ch\int21h\code ends\end begin8.分别统计3个班级中某科成绩优秀的人数和不及格的人数。

data segmenttongji db6dup(?)grade db25,42,95,77db12,0,85,97db92,99,59,24i dw3\j dw4\n1db?\n2db?\data ends\code segment\assume ds:data,cs:code\start:\mov ax,data\mov ds,ax\mov si,0\mov di,0\mov cx,i\for1:\push cx\mov cx,j\for:\cmp grade[si],60\jge let1\inc n2\ jmp let2\let1:\cmp grade[si],90\jl let2\incn1\let2:\inc si\loop for\mov al,n1\mov ds:[di],al\mov al,n2\mov ds:[di+1],al\add di,2\ mov n1,0\mov n2,0\pop cx\loop for1\mov ah,4ch\ int21h\code ends\end start9.编写程序,将AX寄存器中的16位数分成4组,每组4位,从低到高分别放在AL、BL、CL、DL中。

相关主题