[实验目的]
- 熟悉8086宏汇编实验环境,包括编辑(NotePad)、汇编MASM、链接LINK、调试debug32、运行等开发环境的使用,学习简单程序调试运行。
- 熟悉微机原理,掌握8086/8088CPU内部结构,熟悉8086/8088指令系统。
- 熟练掌握汇编语言程序设计方法,通过本实验初步培养计算机逻辑解题能力,熟练掌握有符号数的输入输出方法;掌握选择、循环程序的设计方法,掌握过程设计方法。
[实验要求]
在规定期限独立完成实验内容
- 提交实验报告(电子版)
- 2.提交相应源程序文件
[实验内容]
按要求编写以下程序:各种进制数显示程序
1.在屏幕上显示输出一个十进制数(无符号数显示)(去掉前面多余的0)
1)输出一个十进制数(去掉前面多余的0) data segment dat1 dw 400 flag dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax mov bx,dat1 call dec_show mov ah,4ch int 21h 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
2.将一个数组中所有数据在在屏幕上显示输出(无符号数显示)
2)数组中所有数据显示输出(无符号数) data segment arr dw 38,28,100,6,92,47,502,32400,605,883 n dw 10 flag dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax lea si,arr mov cx,n t: mov bx,[si] call dec_show call space_show add si,2 loop t mov ah,4ch int 21h 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 code ends end begin
3.在屏幕上显示输出一个十进制数(带符号数显示)在屏幕上将一个数以二进制、十六进制、十进制(无符号数)分别显示输出
3)十进制数(带符号数显示)在屏幕上将一个数以二进制、十六进制、十进制(无符号数)分别显示输出 data segment dat1 dw 0ffh data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call bin_show call hex_show call dec_show mov ah,4ch int 21h hex_show proc mov bx,dat1 mov cx,4 t2: push cx mov cl,4 rol bx,cl pop cx mov dl,bl and dl,0fh add dl,30h cmp dl,39h jbe print add dl,7 print: mov ah,2 int 21h loop t2 ret hex_show endp bin_show proc mov bx,dat1 mov cx,16 t1: rol bx,1 mov dl,bl and dl,01h add dl,30h mov ah,2 int 21h loop t1 ret bin_show endp dec_show proc mov bx,dat1 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 add dl,30h mov ah,2 int 21h ret dec_div endp code ends end begin
4.将一个数组中所有数据在在屏幕上显示输出(带符号数显示)
1.4)数组中所有数据在在屏幕上显示输出(带符号数显示) data segment arr dw 38,-28,100,6,-92,47,502,-32400,605,-883 n dw 10 flag dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call arr_show mov ah,4ch int 21h 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_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 code ends end begin
5.求数组元素中最大数并显示(带符号数)
5)求数组元素中最大数并显示(带符号数) data segment arr dw 37,-280,3100,6,-92,427,502,30024,-6305,-883 n dw 10 flag dw ? max dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call arr_show call crlf call findmax mov bx,max call dec_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_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_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.冒泡排序法,要求将数组数据输出、排序、再次输出
6)冒泡排序法,要求将数组数据输出、排序、再次输出 data segment arr dw 38,-28,100,6,-92,47,502,-32400,605,-883 n dw 10 flag dw ? data ends code segment assume cs:code,ds:data begin: mov ax,data mov ds,ax call arr_show call crlf call sort call arr_show call crlf mov ah,4ch int 21h sort proc mov cx,n dec cx mov cx,9 lp1: push cx lea si,arr lp: mov ax,[si] cmp ax,[si+2] jle next xchg ax,[si+2] mov [si],ax next: add si,2 loop lp pop cx loop lp1 ret sort 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_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
[实验截图]