From:https://www.cnblogs.com/Since-natural-ran/p/6938133.html
汇编语言-课程设计1: https://www.cnblogs.com/tsembrace/p/3267158.html
王爽课程设计1(汇编语言编写): https://www.imooc.com/article/18785
王爽《汇编语言》课程设计1: https://blog.csdn.net/zhangyuzuishuai/article/details/52274104
预备知识:
清屏:若要显示这些数据,不希望被之前的信息所影响,所以先把屏幕清理;
assume cs:codestack segmentdw 16 dup(0)code segmentstart:mov ax,stackmov ss,axmov sp,16mov ax,0b800hmov es,axpush bp ;保留现场,虽然没什么用,但是要养成习惯push cxmov bp,0 ;行mov cx,22 ;一共有22行需要清屏s1:mov si,0push cxmov cx,80 ;每一行有80个字符s2:mov byte ptr es:[bp+si],0 ;空字符mov byte ptr es:[bp+si+1],7 ;属性add si,2loop s2add bp,160pop cxloop s1pop cxpop bpmov ax,4c00h ;不要忘了正常退出int 21h
code ends
end start
写成函数的形式:
assume cs:codestack segmentdw 16 dup(0)code segment
start:main:mov ax,stackmov ss,axmov sp,16mov ax,0b800hmov es,axcall sub1mov ax,4c00h ;不要忘了正常退出int 21hsub1:push bp ;保留现场,虽然没什么用,但是要养成习惯push cxmov bp,0 ;行mov cx,22 ;一共有22行需要清屏s1:mov si,0push cxmov cx,80 ;每一行有80个字符s2:mov byte ptr es:[bp+si],0 ;空字符mov byte ptr es:[bp+si+1],7 ;属性add si,2loop s2add bp,160pop cxloop s1pop cxpop bpretcode ends
end start
效果相同
对于字符串的显示程序:
assume cs:codestack segmentdw 16 dup (0)
stack endsdata segmentdb '1975','1976','1977','1978','1979','1980','1981','1982','1983'db '1984','1985','1986','1987','1988','1989','1990','1991','1992'db '1993','1994','1995'
data endscode segment
start:main:mov ax,stackmov ss,axmov sp,16mov ax,datamov ds,axmov ax,0b800h ;显示段mov es,axmov bx,0mov bp,160 ;行add bp,160mov cx,21s1:mov si,0 ;列push cxmov cx,4s2:call show_yearadd si,2inc bxloop s2add bp,160pop cxloop s1mov ax,4c00hint 21hshow_year:push axmov al,[bx]mov es:[bp+si],almov byte ptr es:[bp+si+1],02h ;注意这里要用byte ptrpop axret
code ends
end start
要求:把试验七的数据显示在屏幕上
assume cs:code
stack segmentdw 0,0,0,0,0,0,0,0
stack ends
;******************************数据段******************************
data segmentdb '1975','1976','1977','1978','1979','1980','1981','1982','1983'db '1984','1985','1986','1987','1988','1989','1990','1991','1992'db '1993','1994','1995'; 21个年份的字符串dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514dd 345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000;21年公司收入数据dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635dw 8226,11542,14430,15257,17800;21年公司员工人数dd 21 dup (0) ;21个人均年收入dw 10
data endscode segment
start:mov ax,stackmov ss,axmov sp,16mov ax,datamov ds,axmov ax,0b800hmov es,ax;计算人均收入mov si,84mov di,168mov bx,210mov cx,21jisuan:call div_ddadd si,4add di,2add bx,4loop jisuan
;清屏call clear_scr
;显示年份数据mov bx,0mov bp,160mov cx,21year1:mov si,0push cxmov cx,4year2:call show_yearadd si,2inc bxloop year2add bp,160pop cxloop year1;显示收入数据mov bx,84mov bp,180mov cx,21shouru:mov di,0call show_shouruadd bx,4add bp,160loop shouru
;显示员工数据mov bx,168mov bp,200mov cx,21yuangong:mov di,0call word_showadd bx,2add bp,160loop yuangong
;显示人均收入mov bx,210mov bp,220mov cx,21renjun:mov di,0call show_shouruadd bx,4add bp,160loop renjunmov ax,4c00hint 21h;dd除法运算
div_dd:push axpush dxmov dx,0mov ax,[si+2]div word ptr [di]mov [bx+2],axmov ax,[si]div word ptr [di]mov [bx],axpop dxpop axret;清屏
clear_scr:push bppush cxmov bp,0mov cx,22clear1:mov si,0push cxmov cx,80clear2:mov byte ptr es:[bp+si],0168mov byte ptr es:[bp+si+1],0add si,2loop clear2add bp,160pop cxloop clear1pop cxpop bpret;显示一个字节的字符year
show_year:push axmov al,[bx]mov es:[bp+si],almov byte ptr es:[bp+si+1],02hpop axret;显示dword型数据为字符串,存入显示区域
show_shouru:push axpush bxpush cxpush dxpush simov dx,ds:[bx+2]mov ax,ds:[bx]mov si,0s1:push axmov ax,dxmov dx,0div word ptr ds:[294]mov bx,axpop axdiv word ptr ds:[294]push dxinc simov dx,bxmov cx,axjcxz ok1jmp short s1ok1:mov cx,dxjcxz ok2jmp short s1ok2:mov cx,sis2:pop axadd al,30hmov es:[bp+di],almov byte ptr es:[bp+di+1],02hadd di,2loop s2pop sipop dxpop cxpop bxpop axret;转换word型数据为字符串
word_show:push axpush bxpush cxpush dxpush simov ax,ds:[bx]mov si,0s3:mov bl,almov al,ahmov ah,0div byte ptr ds:[294]mov bh,almov al,bldiv byte ptr ds:[294]mov bl,ahmov ah,bhpush bxmov cx,axinc sijcxz ok3jmp short s3ok3:mov cx,sis4:pop axadd al,30hmov es:[bp+di],almov byte ptr es:[bp+di+1],02hadd di,2loop s4pop sipop dxpop cxpop bxpop axretcode ends
end start
运行结果截图: