| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:asm2In Reply To:asm2 Posted by:vkntu at 2008-12-01 18:58:58 > .model large > .stack 64 > .data > num1 db 6 dup(' ') > num2 db 6 dup(' ') > num3 db 6 dup(' '),"$" > num dw 0 > num11 dw 0 > dolar db "$" > msg1 db 13,10,"num1 : $",13,10 > msg2 db 13,10,"num2 : $",13,10 > msg3 db 13,10,"res : $",13,10 > .code > main proc far > mov ax,@data > mov ds,ax > > call cls > > mov ah,9 > lea dx,msg1 > int 21h > > lea dx,num1 > call get_num > mov bx,num > mov num11,bx > > mov ah,9 > lea dx,msg2 > int 21h > > lea dx,num2 > call get_num > mov bx,num > add bx,num11 > > mov ax,bx > mov dx,0 > mov cx,10 > div cx > add dl,30h > lea si,num3 > mov [si],dl > > cmp ax,0 > jz l1 > mov dx,0 > div cx > add dl,30h > mov [si+1],dl > > cmp ax,0 > jz l1 > mov dx,0 > div cx > add dl,30h > mov [si+2],dl > > cmp ax,0 > jz l1 > mov dx,0 > div cx > add dl,30h > mov [si+3],dl > > cmp ax,0 > jz l1 > mov dx,0 > div cx > add dl,30h > mov [si+4],dl > > cmp ax,0 > jz l1 > mov dx,0 > div cx > add dl,30h > mov [si+5],dl > > l1: > mov ah,9 > lea dx,msg3 > int 21h > > mov ah,9 > lea dx,num3 > int 21h > > mov ax,4c00h > int 21h > main endp > > cls proc far > push ax > push bx > push dx > pushf > mov ah, 6h ;clear screen > mov al, 25 ;number of rows > mov ch, 0 > mov cl, 0 > mov dh, 24 ;row > mov dl, 79 ;column > mov bh, 7 ;attribute > int 10h > popf > pop dx > pop bx > pop ax > > retf > > cls endp > get_num proc far > push bp > mov bp, sp > push si > push bx > push cx > push dx > > > mov ah, 3fh > mov dx, [bp+06] > mov bx, 0000h > mov cx,8 > int 21h > > > mov si, dx > while_blank: cmp byte ptr [bx], ' ' ; skip leading blank > jne end_while_blank ; exit while > inc bx > jmp while_blank > end_while_blank: > mov bl, 1 ;default sign multiplier > cmp byte ptr [si], '+' ;leadin + ? > je skip_sign ;if so skip over > cmp byte ptr [si], '-' ;leading - ? > jne save_sign ;if not save default + > mov bl, -1 ;-1 for minus sign > skip_sign: inc si ;past sign > > save_sign: mov ax, 0 ;number being accumulated > mov bh, 0 ;count of digits so far > while_digit: cmp byte ptr [si], '0' ;compare next car to '0' > jl end_while_digit ;if not a digit exit > cmp byte ptr [si], '9' ;compare to '9' > jg end_while_digit ;not a digit if bigger than '9' > mov cx, 10 ;multiplier > mul cx ;multiply old number by 10 > mov cl, [si] ;mov ascii char to bl > and cx, 000fh ;convert to single digit integer > add ax, cx ;add to sum > inc bh ;increment digit count > inc si ;increment character pointer > jmp while_digit ;go next char > end_while_digit: > ; imul bl > cmp bl, 1 > je exit1 > neg ax > exit1: > mov num, ax > > pop dx > pop bx > pop cx > pop si > pop bp > > retf 2 > get_num endp > > > convert_num_string proc far > > push bp > mov bp, sp > push si > push ax > push bx > push cx > push dx > mov ax, word ptr[bp+08] > mov si, word ptr[bp+06] > > add si, 5 > mov bh, ' ' > cmp ax, 0 > jge setup ; skip if not negative > mov bh, '-' > neg ax ; now ax > 0 > > setup: mov cx, 10 ; divisor > divloop: mov dx, 0 ; extend number to double word > div cx ; divide by 10 > add dl, 30h ; convert > mov [si], dl > dec si > cmp ax, 0 > jne divloop > mov cl, bh ; insert sign to string > mov [si], cl > > pop dx > pop bx > pop cx > pop ax > pop si > pop bp > > retf 4 > > convert_num_string endp > end main Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator