[实验目的]
- 熟悉8086宏汇编实验环境,包括编辑(NotePad)、汇编MASM、链接LINK、调试debug32、运行等开发环境的使用,学习简单程序调试运行。
- 熟悉微机原理,掌握8086/8088CPU内部结构,熟悉8086/8088指令系统。
- 熟练掌握汇编语言程序设计方法,通过本实验初步培养计算机逻辑解题能力,熟练掌握十进制输的输入输出方法;掌握字符串的操作方法。
[实验要求]
在规定期限独立完成实验内容
- 提交实验报告(电子版)
- 2.提交相应源程序文件
[实验内容]
按要求编写以下程序:十进制输入、数组中负数个数、字符串比较程序
1.从键盘输入一个十进制数(无符号数)并在屏幕上显示输出
1)输入一个十进制数(无符号数) data segment flag dw ? dat1 dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call dec_in mov dat1,bx call dec_show mov ah,4ch int 21h dec_in proc mov bx,0 indig: mov ah,1 int 21h sub al,30h jb exit2 cmp al,9 ja exit2 cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp indig exit2:ret dec_in endp dec_show proc mov flag,1 mov cx,10000 call dec_div mov cx,1000 call dec_div mov cx,100 call dec_div mov cx,10 call dec_div mov cx,1 call dec_div ret dec_show endp dec_div proc mov dx,0 mov ax,bx div cx mov bx,dx mov dl,al cmp dl,0 jnz print cmp flag,1 jz exit print: add dl,30h mov ah,2 int 21h mov flag,0 exit: ret dec_div endp code ends end begin
2.从键盘输入一个十进制数(带符号数)并在屏幕上显示输出
2)输入一个十进制数(带符号数) data segment flag dw ? dat1 dw ? f2 dw 0 data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call f_dec_in mov dat1,bx call f_dec_show mov ah,4ch int 21h f_dec_in proc mov bx,0 mov ah,1 int 21h cmp al,'-' jnz posi mov f2,1 jmp nega posi: sub al,30h mov ah,0 mov bx,ax nega: call dec_in cmp f2,1 jnz e3 neg bx e3: ret f_dec_in endp dec_in proc indig: mov ah,1 int 21h sub al,30h jb exit2 cmp al,9 ja exit2 cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp indig exit2:ret dec_in endp f_dec_show proc and bx,bx jns show mov dl,'-' mov ah,2 int 21h neg bx show: call dec_show ret f_dec_show endp dec_show proc push cx mov flag,1 mov cx,10000 call dec_div mov cx,1000 call dec_div mov cx,100 call dec_div mov cx,10 call dec_div mov cx,1 call dec_div pop cx ret dec_show endp dec_div proc mov dx,0 mov ax,bx div cx mov bx,dx mov dl,al cmp dl,0 jnz print cmp flag,1 jz exit print: add dl,30h mov ah,2 int 21h mov flag,0 exit: ret dec_div endp code ends end begin
3.从键盘输入若干个十进制数(带符号数)存入数组中并显示
3)输入若干个十进制数(带符号数)存入数组中 data segment arr dw -3,78,88,95,44,-67,70,-345,-565 n dw 9 flag dw ? dat1 dw ? f2 dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call arr_in call arr_show mov ah,4ch int 21h arr_in proc lea si,arr mov cx,n t1: call f_dec_in mov [si],bx add si,2 loop t1 ret arr_in endp arr_show proc lea si,arr mov cx,n t: mov bx,[si] call f_dec_show call space_show add si,2 loop t ret arr_show endp f_dec_in proc push cx mov f2,0 mov bx,0 mov ah,1 int 21h cmp al,'-' jnz posi mov f2,1 jmp nega posi: sub al,30h mov ah,0 mov bx,ax nega: call dec_in cmp f2,1 jnz e3 neg bx e3: pop cx ret f_dec_in endp dec_in proc indig: mov ah,1 int 21h sub al,30h jb exit2 cmp al,9 ja exit2 cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp indig exit2:ret dec_in endp f_dec_show proc and bx,bx jns show mov dl,'-' mov ah,2 int 21h neg bx show: call dec_show ret f_dec_show endp dec_show proc push cx mov flag,1 mov cx,10000 call dec_div mov cx,1000 call dec_div mov cx,100 call dec_div mov cx,10 call dec_div mov cx,1 call dec_div pop cx ret dec_show endp dec_div proc mov dx,0 mov ax,bx div cx mov bx,dx mov dl,al cmp dl,0 jnz print cmp flag,1 jz exit print: add dl,30h mov ah,2 int 21h mov flag,0 exit: ret dec_div endp space_show proc mov dl,20h mov ah,2 int 21h ret space_show endp crlf proc mov dl,0dh mov ah,2 int 21h mov dl,0ah mov ah,2 int 21h ret crlf endp code ends end begin
4.求数组元素中最大数并显示(带符号数),要求数组中数据从键盘输入
4)数组元素中最大数并显示(带符号数) data segment arr dw 13,33,-18,99,987,-345,3455,-09,-8769,22 n dw 10 max dw ? flag dw ? dat1 dw ? f2 dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call arr_in call findmax mov bx,max call f_dec_show ;call arr_show mov ah,4ch int 21h findmax proc lea si,arr mov ax,[si] add si,2 mov cx,n dec n t2: cmp ax,[si] jge next mov ax,[si] next: add si,2 loop t2 mov max,ax ret findmax endp arr_in proc lea si,arr mov cx,n t1: call f_dec_in mov [si],bx add si,2 loop t1 ret arr_in endp arr_show proc lea si,arr mov cx,n t: mov bx,[si] call f_dec_show call space_show add si,2 loop t ret arr_show endp f_dec_in proc push cx mov f2,0 mov bx,0 mov ah,1 int 21h cmp al,'-' jnz posi mov f2,1 jmp nega posi: sub al,30h mov ah,0 mov bx,ax nega: call dec_in cmp f2,1 jnz e3 neg bx e3: pop cx ret f_dec_in endp dec_in proc indig: mov ah,1 int 21h sub al,30h jb exit2 cmp al,9 ja exit2 cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp indig exit2:ret dec_in endp f_dec_show proc and bx,bx jns show mov dl,'-' mov ah,2 int 21h neg bx show: call dec_show ret f_dec_show endp dec_show proc push cx mov flag,1 mov cx,10000 call dec_div mov cx,1000 call dec_div mov cx,100 call dec_div mov cx,10 call dec_div mov cx,1 call dec_div pop cx ret dec_show endp dec_div proc mov dx,0 mov ax,bx div cx mov bx,dx mov dl,al cmp dl,0 jnz print cmp flag,1 jz exit print: add dl,30h mov ah,2 int 21h mov flag,0 exit: ret dec_div endp space_show proc mov dl,20h mov ah,2 int 21h ret space_show endp crlf proc mov dl,0dh mov ah,2 int 21h mov dl,0ah mov ah,2 int 21h ret crlf endp code ends end begin
5.求数组元素中负数的个数并显示(带符号数),要求数组中数据从键盘输入
5)数组元素中负数的个数并显示(带符号数) data segment arr dw 13,33,-18,99,987,-345,3455,-09,-8769,22 n dw 10 flag dw ? dat1 dw ? f2 dw ? num dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call arr_in call count_neg mov bx,num call f_dec_show ;call arr_show mov ah,4ch int 21h count_neg proc mov bx,0 lea si,arr mov cx,n t2: mov ax,[si] cmp ax,0 jge next inc bx next: add si,2 loop t2 mov num,bx ret count_neg endp arr_in proc lea si,arr mov cx,n t1: call f_dec_in mov [si],bx add si,2 loop t1 ret arr_in endp arr_show proc lea si,arr mov cx,n t: mov bx,[si] call f_dec_show call space_show add si,2 loop t ret arr_show endp f_dec_in proc push cx mov f2,0 mov bx,0 mov ah,1 int 21h cmp al,'-' jnz posi mov f2,1 jmp nega posi: sub al,30h mov ah,0 mov bx,ax nega: call dec_in cmp f2,1 jnz e3 neg bx e3: pop cx ret f_dec_in endp dec_in proc indig: mov ah,1 int 21h sub al,30h jb exit2 cmp al,9 ja exit2 cbw xchg ax,bx mov cx,10 mul cx xchg ax,bx add bx,ax jmp indig exit2:ret dec_in endp f_dec_show proc and bx,bx jns show mov dl,'-' mov ah,2 int 21h neg bx show: call dec_show ret f_dec_show endp dec_show proc push cx mov flag,1 mov cx,10000 call dec_div mov cx,1000 call dec_div mov cx,100 call dec_div mov cx,10 call dec_div mov cx,1 call dec_div pop cx ret dec_show endp dec_div proc mov dx,0 mov ax,bx div cx mov bx,dx mov dl,al cmp dl,0 jnz print cmp flag,1 jz exit print: add dl,30h mov ah,2 int 21h mov flag,0 exit: ret dec_div endp space_show proc mov dl,20h mov ah,2 int 21h ret space_show endp crlf proc mov dl,0dh mov ah,2 int 21h mov dl,0ah mov ah,2 int 21h ret crlf endp code ends end begin
6.密码输入及验证程序。从键盘输入密码,与程序中设定的原始密码比较,若正确,显示“welcome!!”,若错误,提示错误信息“wrong!!”并要求再次输入,若输入3次密码错误,显示“sorry!!password iswrong。。”并退出程序。
6)密码输入及验证程序 data segment pass db 'gegegege' n equ $ - pass pasbuf db 20 db ? db 20 dup(?) mess1 db 'password:','$' mess2 db 'welcome!!!$' mess3 db 'wrong!!please try agin...',0dh,0ah,'$' mess4 db 'sorry...password is wrong',0dh,0ah,'$' data ends code segment assume cs:code,ds:data,es:data begin: mov ax,data mov ds,ax mov es,ax mov bx,3 t: lea dx,mess1 mov ah,9 int 21h lea dx,pasbuf mov ah,0ah int 21h lea si,pass lea di,pasbuf cmp byte ptr[di+1],n jne err_show add di,2 mov cx,n cld repe cmpsb jne err_show lea dx,mess2 call crlf mov ah,9 int 21h jmp exit err_show:call crlf lea dx,mess3 mov ah,9 int 21h dec bx jnz t lea dx,mess4 mov ah,9 int 21h exit: mov ah,4ch int 21h crlf proc push ax push dx mov dl,0dh mov ah,2 int 21h mov dl,0ah mov ah,2 int 21h pop dx pop ax ret crlf endp code ends end begin
[实验截图]