
November 27th, 2006, 11:31 PM
|
|
|
|
8086 32 bit integer input
yeah im working on a project for school and i need the integer input to work on 32 to bit and its working only up to 16 bits haven't been able to figure whats its the bug so im gonna post my proc in hope someone can find it. Basically i need Dx to have the first 16 bits and ax the last 16.
Code:
;A procedure that sums BX-AX and DX-CX
;the result is returned in BX-AX
longadd proc
add ax,cx
adc bx,dx
ret
longadd endp
;reads a number and place on dx:ax
readn proc near
push cx
push bx ; saving the other registers
push bp
mov bp , 0
mov cx , 10 ; make cx 10
mov bx , 0 ;set to 0
mov dx , 0 ; set to 0
readn1:
mov ah , 1 ;make ah 1 in order to call interrup of one char with echo
int 21h ;activate the interrupt
cmp al , 13d
je readn2
cmp al , '0' ;if its < 0 ends the loop
jb set0
cmp al , '9'
ja set0 ; if its >9 ends the loop
sub al , '0' ; turn the char into decimal
push ax ;saves ax
mov ax ,dx ;places the value from dx into ax for mult
mul cx ; mult by 10
mov dx ,ax ;restore dx mult by 10
mov ax ,bx ;makes ax bx for mult
mul cx ;mult by 10
mov bx ,ax ;restore bx mult by 10
pop ax ; restore ax to value before mult
mov ah , 0 ;makes ah 0
push ax ;saves variables
push cx ;set stuff for long adding
mov cx , ax
mov ax , bx
mov bx , dx
mov dx , 0
call longadd ; long add happens
mov dx ,bx
mov bx , ax
pop cx
pop ax
jmp readn1 ; goes back to start of the loop
set0:
mov bp , 1 ; uses bp to hold a flag for when ilegal input occurs
jmp readn1
set02:
xor dx ,dx ;makes them 0 due to ilegal input
xor ax ,ax
mov bp , 0
readn2: ;checks if it there was an error and gives output
mov ax,bx
cmp bp ,1
je set02
tend1: ;returns variables
pop bp
pop bx
pop cx
ret ;ends proc
readn endp
|