欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

汇编语言寻址练习

程序员文章站 2024-02-02 15:50:10
...
assume ds:data,ss:stack,cs:code
data segment
    db '2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019'
    dd 50200, 60590, 61883, 50440, 59403, 56804, 50375, 55397, 56491, 63885, 62629, 53736, 60995
    dd 43941, 52778, 54517, 46239, 53533, 49623, 43690, 53436, 52877, 63831, 55768, 52660, 53184
data ends

table segment
    db 13 dup ('year end balance ??  ')
table ends

stack segment
    dw 32 dup (0)
stack ends

buffer segment
    db 32 dup (0),'$'
buffer ends

code  segment
    start:
        mov ax,data
        mov ds,ax

        mov ax,stack
        mov ss,ax
        mov sp,32
		
		mov ax,table
        mov es,ax
        mov bx,0
		
		call clear_screen
		call copy_data
		; 将数据转成字符串放入缓存
		
		push ax
		mov ax,buffer
		mov ds,ax
		pop ax

		mov bx,0
		mov si,0
		mov di,0
		mov bx,160
		mov cx,13
		lp_m1:
			
			mov ax, es:[di]
			mov dx, es:[di + 2]
			mov ds:[0], ax
            mov ds:[2], dx
			
			mov ax,es:[di + 5]
			mov dx,es:[di + 7]
			
			mov si, 5
			call dtoc_buffer
			
			mov ax, es:[di + 10]
			mov dx, es:[di + 12]
			
			inc si
			call dtoc_buffer

			push si
			push di
			push bx
			mov ax, es:[di + 5]
			mov bx, es:[di + 7]
			mov si, es:[di + 10]
			mov di, es:[di + 12]
			
			push cx
			call divi
			mov ax, cx
			pop cx
			
			pop bx
			pop di
			pop si

			inc si 
			call dtoc_buffer
			
			call show_buffer
			add di, 21
			add bx,160
		loop lp_m1
				
		mov ax, 4c00h
        int 21h
		
	; 25 row
    ; 80 column	
	clear_screen:
	    push ax
        push bx
        push cx
		push es
		
		mov ax,0b800h
		mov es,ax
		
        mov bx,0
        mov cx,25
	    lp_c1:
            mov si,0
            push cx
            mov cx,80
			lp_c2:
				mov byte ptr es:[bx + si],0168
				mov byte ptr es:[bx + si + 1],0
				add si,2
			loop lp_c2
            add bx,160
            pop cx
        loop lp_c1
        
		pop es
		pop cx
        pop bx
		pop ax
    ret
		
	copy_data:
	    push ax
	    push bx
		push cx
		push dx
		push ds
		push di
		
		mov di,0
		mov bx,0;
		mov cx,13 ; 13 row
		lp_cd:
		    mov ax,ds:[di]
            mov es:[bx],ax
            mov ax,ds:[di + 2]
            mov es:[bx + 2],ax
			
			mov ax,ds:[di + 4 * 13]
			mov dx,ds:[di + 4 * 13 + 2]
			mov es:[bx + 5],ax
			mov es:[bx + 5 + 2],dx
			
			mov ax, ds:[di + 4 * 13 + 4 * 13]
			mov dx, ds:[di + 4 * 13 + 4 * 13 + 2]
			mov es:[bx + 0ah],ax
			mov es:[bx + 0ch],dx
			
			add di,4
			add bx,21			
		loop lp_cd
	    pop di
		pop ds
		pop dx
		pop cx
		pop bx
		pop ax
	ret
	
	show_buffer:
		push ax
		push si
		push di
		push es
		push dx
		push cx
		
		mov ax,0b800h
		mov es,ax
		mov si,0
		mov di,0
	 s4:
		mov ch,0
		mov cl,ds:[si]
		cmp cl, '$' 
		je s3
		jmp continue
	continue:
		mov dl,0
		mov ds:[si],dl
		mov ah,00000010b
		mov al,cl
		mov es:[bx + di],ax
		add di,2
		inc si
		jmp short s4
	 s3:
		pop cx
		pop dx
	    pop es
		pop di
		pop si
		pop ax
	ret
		
    dtoc_buffer:
		push di
		push cx
		push bx
			 
		mov di,0
        mov bx,0
	 k1:push ax
		mov cx,0ah
		mov ax,dx
		mov dx,0
		div cx

		mov bx,ax
		pop ax
		mov cx,ax
		jcxz k2
		mov cx,0ah
		div cx
		mov cx,dx
		mov dx,bx

		add cx,30h
		push cx
		inc di
		jmp short k1

	k2: 
	k4: mov cx,di
		jcxz k3
		pop ds:[si]
		inc si
		dec di
		jmp short k4
	 k3:pop bx            
		pop cx
		pop di
		ret
		
        divi:
             push ax
             push bx
             push si
             push di

             mov cx, ax
             mov dx, bx
             sub dx, di
             sbb cx, si

             pop di
             pop si
             pop bx
             pop ax
	ret

	
code  ends
end start

代码缺陷:
除法不支持负数
以后慢慢修改,系统能给你提供帮助

相关标签: 汇编