assume cs:codesg,ds:datasg,ss:stacksg datasg segment db 2h ;绿色 ;0h db 24h ;绿底红色 ;1h db 71h ;白底蓝色 ;2h db 'welcome to masm!',0 ;text ;3h db 16 dup(0) ;14h db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','19
- assume cs:codesg,ds:datasg,ss:stacksg
- datasg segment
- db 2h ;绿色 ;0h
- db 24h ;绿底红色 ;1h
- db 71h ;白底蓝色 ;2h
- db 'welcome to masm!',0 ;text ;3h
- db 16 dup(0) ;14h
- db '1975','1976','1977','1978','1979','1980','1981','1982','1983','1984','1985','1986','1987','1988','1989','1990','1991','1992','1993','1994','1995' ;24h
- dd 16,22,382,1356,2390,8000,16000,24486,50065,97479,140417,197514,345980,590827,803530,1183000,1843000,2759000,3753000,4649000,5937000 ;78h
- dw 3,7,9,13,28,38,130,220,476,778,1001,1442,2258,2793,4037,5635,8226,11542,14430,15257,17800 ;0cch
- db 64 dup(0) ;字缓冲 ;0f6h
- datasg ends
- table segment
- dd 21 dup (0,0,0,0)
- table ends
- stacksg segment
- dd 16 dup (0)
- stacksg ends
- codesg segment
- ;--------------------------------------------------------showStr-------------------------------------------------------------------------------
- showStr:push bp;(byte->height(+9h)_byte->width(+8h),byte_byte->color(+6h),word->text_addr(+4h))(无返回,已恢复栈)
- mov bp,sp
- push ax
- push bx
- push cx
- push dx
- push di
- push si
- push es
- ;计算所在行数
- mov al,ss:9h[bp];获取行数
- mov bl,160;每行160个字节
- mul bl;行数x每行字节数
- push ax;保存下结果
- ;计算所在列数
- mov al,ss:8h[bp];获取列数
- mov bl,2h;你懂的...
- mul bl;
- pop bx
- add ax,bx;定位显存位置
- mov si,ax;保存一下
- ;显示
- mov di,0
- mov bx,ss:4h[bp]
- mov ax,0b800h
- mov es,ax
- for1:mov cl,ds:[bx][di];循环每个字符,复制到显示缓冲区,并加上色
- mov ch,0
- jcxz return
- mov byte ptr es:[si],cl;复制字符
- inc si
- mov ch,ss:6h[bp];获取颜色参数
- mov byte ptr es:[si],ch;设置颜色
- inc si
- inc di
- loop for1
- return:pop ax
- mov es,ax
- pop si
- pop di
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- ret 6h
- ;--------------------------------------------------------showStr-------------------------------------------------------------------------------
- ;--------------------------------------------------------divdw---------------------------------------------------------------------------------
- divdw:push bp;(word->dividl(+8h),word->dividh(+6h),word->divish(+4h))(有返回(pop(+4h余),pop(+6h结果高位),pop(+8h结果低位)),自行恢复栈)
- mov bp,sp
- push ax
- push bx
- push cx
- push dx
- mov dx,0
- mov ax,ss:6h[bp]
- div word ptr ss:4h[bp]
- mov word ptr ss:6h[bp],ax;32位结果的高位
- mov ax,word ptr ss:8h[bp]
- div word ptr ss:4h[bp];欧几里德同余公式,被搞死...郁闷
- mov word ptr ss:8h[bp],ax;32位结果的底位
- mov word ptr ss:4h[bp],dx;32位结果的余
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- ret
- ;--------------------------------------------------------divdw---------------------------------------------------------------------------------
- ;--------------------------------------------------------dtoc----------------------------------------------------------------------------------
- dtoc:push bp;(word->numl(+8h),word->numh(+6h),word->txt_addr(+4h))(无返回,已恢复栈)
- mov bp,sp
- push di
- push ax
- push dx
- push bx
- push cx
- push si
- mov si,0;转换计数
- mov di,ss:4h[bp];获取存放字符串的地址
- mov ax,ss:8h[bp];获取被除数低位
- push ax
- mov ax,ss:6h[bp];获取被除数高位
- push ax
- mov ax,10;设置除数
- push ax
- call divdw
- pop cx
- pop dx
- pop ax
- jmp dtoc_go
- dtoc_to:push ax
- push dx
- mov ax,10
- push ax
- call divdw
- pop cx
- pop dx
- pop ax
- dtoc_go:add cx,30h;数字转字符
- push cx;保存结果
- inc si
- mov cx,ax;先检查结果的低位等不等于0
- jcxz dtoc_ch;如果等于转到dtoc_ch检查高位
- jmp dtoc_to;否则继续转换
- dtoc_ch:mov cx,dx;检查高位等不等于0
- jcxz dtoc_fl;高位和低位都为0,除完...你懂的
- jmp dtoc_to;不用看了,继续转吧...
- dtoc_fl:mov cx,si
- jcxz dtoc_f
- dtoc_l1:pop ax
- mov ds:[di],al;设置正确结果
- inc di
- loop dtoc_l1
- dtoc_f:pop si
- pop cx
- pop bx
- pop dx
- pop ax
- pop di
- pop bp
- ret 6h
- ;--------------------------------------------------------dtoc----------------------------------------------------------------------------------
- ;--------------------------------------------------------cl_mem--------------------------------------------------------------------------------
- cl_mem:push cx;清空下字节缓冲
- push si
- mov si,0
- mov cx,40h
- clm_s:mov byte ptr ds:0f6h[si],0h
- inc si
- loop clm_s
- pop si
- pop cx
- ret
- ;--------------------------------------------------------cl_mem--------------------------------------------------------------------------------
- start:mov ax,datasg
- mov ds,ax
- mov ax,stacksg
- mov ss,ax
- mov sp,40h
- mov ax,table
- mov es,ax
- mov si,0;设置表格
- mov di,0
- mov cx,21
- main_s:mov bx,24h;年份
- mov ax,ds:[bx].2[si]
- mov dx,ds:[bx][si]
- mov es:2[di],ax
- mov es:[di],dx
- mov bx,78h;收入
- mov ax,ds:[bx].2[si]
- mov dx,ds:[bx][si]
- mov es:[di].7,ax
- mov es:[di].5,dx
- mov ax,si
- mov bl,2
- div bl
- mov ah,0
- mov dx,ax
- mov bp,si
- mov si,dx
- mov bx,0cch;雇员数
- mov ax,ds:[bx][si]
- mov es:[di].0ah,ax
- mov si,bp
- mov ax,es:[di].5;人均收入
- mov dx,es:[di].7
- div word ptr es:[di].0ah
- mov es:[di].0dh,ax
- add si,4
- add di,10h
- loop main_s
- ;---------------------------------------------------------------------------------------------------------------------------------------
- mov di,0
- mov si,10
- mov bx,10
- mov cx,21
- main_set:call cl_mem;清空下显示缓冲区
- mov ax,es:[di]
- mov ds:[0f6h],ax
- mov ax,es:[di].2h
- mov ds:[0f8h],ax;复制年份到显示到显示缓冲区
- mov ah,bl
- mov al,20
- push ax
- mov ah,0
- mov al,0fh
- push ax
- mov ax,0f6h
- push ax
- call showStr;显示年份
- call cl_mem;清空下显示缓冲区
- mov ax,es:5h[di]
- push ax
- mov ax,es:7h[di]
- push ax
- mov ax,0f6h
- push ax
- call dtoc
- mov ah,bl
- mov al,30
- push ax
- mov ah,0
- mov al,0fh
- push ax
- mov ax,0f6h
- push ax
- call showStr;显示收入
- call cl_mem;清空下显示缓冲区
- mov ax,es:0ah[di]
- push ax
- mov ax,0
- push ax
- mov ax,0f6h
- push ax
- call dtoc
- mov ah,bl
- mov al,40
- push ax
- mov ah,0
- mov al,0fh
- push ax
- mov ax,0f6h
- push ax
- call showStr;显示雇员数
- call cl_mem;清空下显示缓冲区
- mov ax,es:0dh[di]
- push ax
- mov ax,0
- push ax
- mov ax,0f6h
- push ax
- call dtoc
- mov ah,bl
- mov al,50
- push ax
- mov ah,0
- mov al,0fh
- push ax
- mov ax,0f6h
- push ax
- call showStr;显示人均收入
- add di,10h
- inc bx
- dec cx
- jcxz game_o
- jmp main_set
- game_o:mov ax,4c00h
- int 21h
- codesg ends
- end start