王爽 汇编语言第三版 课程设计 1

原文链接: https://www.cnblogs.com/Since-natural-ran/p/6938133.html

 

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:code

stack segment
    dw 16 dup(0)

code segment
        start:
            mov ax,stack
            mov ss,ax
            mov sp,16

            mov ax,0b800h
            mov es,ax

            push bp     ;保留现场,虽然没什么用,但是要养成习惯
            push cx
            mov bp,0    ;行
            mov cx,22   ;一共有22行需要清屏
        s1:
            mov si,0
            push cx
            mov cx,80   ;每一行有80个字符
        s2:
            mov byte ptr es:[bp+si],0   ;空字符
            mov byte ptr es:[bp+si+1],7 ;属性
            add si,2
            loop s2
            add bp,160
            pop cx
            loop s1
            pop cx
            pop bp

            mov ax,4c00h                ;不要忘了正常退出
            int 21h
code ends
end start

王爽 汇编语言第三版 课程设计 1_第1张图片

写成函数的形式:

assume cs:code

stack segment
    dw 16 dup(0)

code segment
start:
    main:
            mov ax,stack
            mov ss,ax
            mov sp,16

            mov ax,0b800h
            mov es,ax
            call sub1

            mov ax,4c00h                ;不要忘了正常退出
            int 21h

    sub1:
            push bp     ;保留现场,虽然没什么用,但是要养成习惯
            push cx
            mov bp,0    ;行
            mov cx,22   ;一共有22行需要清屏
        s1:
            mov si,0
            push cx
            mov cx,80   ;每一行有80个字符
        s2:
            mov byte ptr es:[bp+si],0   ;空字符
            mov byte ptr es:[bp+si+1],7 ;属性
            add si,2
            loop s2
            add bp,160
            pop cx
            loop s1
            pop cx
            pop bp
            ret

code ends
end start

效果相同

对于字符串的显示程序:

assume cs:code

stack segment
    dw 16 dup (0)
stack ends

data segment
  db '1975','1976','1977','1978','1979','1980','1981','1982','1983'
  db '1984','1985','1986','1987','1988','1989','1990','1991','1992'
  db '1993','1994','1995'
data ends

code segment
start:
    main:
            mov ax,stack
            mov ss,ax
            mov sp,16

            mov ax,data
            mov ds,ax

            mov ax,0b800h   ;显示段
            mov es,ax

            mov bx,0
            mov bp,160      ;行
            add bp,160
            mov cx,21
        s1:
            mov si,0        ;列
            push cx
            mov cx,4
        s2:
            call show_year
            add si,2
            inc bx
            loop s2
            add bp,160
            pop cx
            loop s1

            mov ax,4c00h
            int 21h

    show_year:
            push ax
            mov al,[bx]
            mov es:[bp+si],al
            mov byte ptr es:[bp+si+1],02h   ;注意这里要用byte ptr
            pop ax
            ret
code ends
end start

  

王爽 汇编语言第三版 课程设计 1_第2张图片

 

要求:把试验七的数据显示在屏幕上

assume cs:code
stack segment
    dw 0,0,0,0,0,0,0,0
stack ends
;******************************数据段******************************
data segment
  db '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,197514
  dd 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,5635
  dw 8226,11542,14430,15257,17800
    ;21年公司员工人数
  dd 21 dup (0)     ;21个人均年收入
  dw 10
data ends

code segment
start:
        mov ax,stack
        mov ss,ax
        mov sp,16

        mov ax,data
        mov ds,ax

        mov ax,0b800h
        mov es,ax

;计算人均收入
        mov si,84
        mov di,168
        mov bx,210
        mov cx,21

    jisuan:
        call div_dd
        add si,4
        add di,2
        add bx,4
        loop jisuan
;清屏
        call clear_scr
;显示年份数据
        mov bx,0
        mov bp,160
        mov cx,21
    year1:
        mov si,0
        push cx
        mov cx,4
    year2:
        call show_year
        add si,2
        inc bx
        loop year2
        add bp,160
        pop cx
        loop year1

;显示收入数据
        mov bx,84
        mov bp,180
        mov cx,21
    shouru:
        mov di,0
        call show_shouru
        add bx,4
        add bp,160
        loop shouru
;显示员工数据
        mov bx,168
        mov bp,200
        mov cx,21
    yuangong:
        mov di,0
        call word_show
        add bx,2
        add bp,160
        loop yuangong
;显示人均收入
        mov bx,210
        mov bp,220
        mov cx,21
    renjun:
        mov di,0
        call show_shouru
        add bx,4
        add bp,160
        loop renjun

        mov ax,4c00h
        int 21h


;dd除法运算
div_dd:
        push ax
        push dx
        mov dx,0
        mov ax,[si+2]
        div word ptr [di]
        mov [bx+2],ax
        mov ax,[si]
        div word ptr [di]
        mov [bx],ax
        pop dx
        pop ax
        ret


;清屏
clear_scr:
        push bp
        push cx
        mov bp,0
        mov cx,22
    clear1:
        mov si,0
        push cx
        mov cx,80
    clear2:
        mov byte ptr es:[bp+si],0168
        mov byte ptr es:[bp+si+1],0
        add si,2
        loop clear2
        add bp,160
        pop cx
        loop clear1
        pop cx
        pop bp
        ret

;显示一个字节的字符year
show_year:
        push ax
        mov al,[bx]
        mov es:[bp+si],al
        mov byte ptr es:[bp+si+1],02h
        pop ax
        ret

;显示dword型数据为字符串,存入显示区域
show_shouru:
        push ax
        push bx
        push cx
        push dx
        push si

        mov dx,ds:[bx+2]
        mov ax,ds:[bx]
        mov si,0
    s1:
        push ax
        mov ax,dx
        mov dx,0
        div word ptr ds:[294]
        mov bx,ax
        pop ax
        div word ptr ds:[294]
        push dx
        inc si
        mov dx,bx
        mov cx,ax
        jcxz ok1
        jmp short s1
    ok1:
        mov cx,dx
        jcxz ok2
        jmp short s1
    ok2:
        mov cx,si
    s2:
        pop ax
        add al,30h
        mov es:[bp+di],al
        mov byte ptr es:[bp+di+1],02h
        add di,2
        loop s2
        pop si
        pop dx
        pop cx
        pop bx
        pop ax
        ret

;转换word型数据为字符串
word_show:
        push ax
        push bx
        push cx
        push dx
        push si
        mov ax,ds:[bx]
        mov si,0
    s3:
        mov bl,al
        mov al,ah
        mov ah,0
        div byte ptr ds:[294]
        mov bh,al
        mov al,bl
        div byte ptr ds:[294]
        mov bl,ah
        mov ah,bh
        push bx
        mov cx,ax
        inc si
        jcxz ok3
        jmp short s3
    ok3:
        mov cx,si
    s4:
        pop ax
        add al,30h
        mov es:[bp+di],al
        mov byte ptr es:[bp+di+1],02h
        add di,2
        loop s4
        pop si
        pop dx
        pop cx
        pop bx
        pop ax
        ret

code ends
end start

运行结果截图:

王爽 汇编语言第三版 课程设计 1_第3张图片

 

 

 

 

你可能感兴趣的:(汇编)