I have a work to do in Assembly. With the value of a radius given by the user, It only calculates the area of a circle. It has to work in 8086 and
not in 80386. I think that the problem is that the value is loaded to the FPU stack as a string. How do I convert a string to a floating point value?
I'm using
MASM 6.14 and I really can't use another compiler.
Can someone please please help me?
.8087
;include include\stdlib.a
; includelib lib\stdlib.lib
.MODEL SMALL
.STACK 200h
; this macro prints a string that is given as a parameter, example:
; PRINTN 'hello world!'
; the same as PRINT, but new line is automatically added.
PRINTN MACRO sdat
LOCAL next_char, s_dcl, printed, skip_dcl
PUSH AX ; store registers...
PUSH SI ;
JMP skip_dcl ; skip declaration.
s_dcl DB sdat, 0Dh,0Ah, 0
skip_dcl:
LEA SI, s_dcl
next_char:
MOV AL, CS:[SI]
CMP AL, 0
JZ printed
INC SI
MOV AH, 0Eh ; teletype function.
INT 10h
JMP next_char
printed:
POP SI ; re-store registers...
POP AX ;
ENDM
data Segment
menu db ' ',0ah,0dh
db ' 2006/2007 ',0ah,0dh
db ' ',0ah,0dh
db ' þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ ',0ah,0dh
db ' þ Computer Architecture þ ',0ah,0dh
db ' þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ ',0ah,0dh
db ' þ 1Calculate Area þ ',0ah,0dh
db ' þ 2HELP þ ',0ah,0dh
db ' þ 3EXIT þ ',0ah,0dh
db ' þþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþþ ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db ' ',0ah,0dh
db 'Choose an option:','$'
mens1 Db 0ah,0ah,0dh,'Introduce the radius:','$'
mens2 Db 0ah,0ah,0dh,'Introduce the second number:','$'
mens3 Db 0ah,0ah,0dh,'The area of the circle is:','$'
menserro db 0ah,0ah,0dh,' (ERROR) Introduce a number between 1 and 5',0ah,0dh,'$'
prima db 0ah,0dh,' Press ENTER and then introduce a number',0ah,0dh,'$'
menserro2 db 0ah,0dh,' (ERROR) Introduce a letter (Y)es or (N)o',0ah,0dh,'$'
prima2 db 0ah,0dh,' Press ENTER and then introduce a letter',0ah,0dh,'$'
nota db 0dh,' NOTe:(Introduce the letters in uppercase)',0ah,0dh,'$'
real Db 0ah,0dh,'Work done by *** and ***',0dh,'$'
sair db 0ah,0ah,0dh,'Quit? Y/N',0ah,0dh,'$'
result db 100 dup (?)
db '$'
num dw 0
valx DW ?
num2 dw 0
posinum dw 32, 16, 32 dup (?)
posinum2 dw 32, 16, 32 dup (?)
convert dw 0001h, 000ah, 0064h, 03E8h, 2710h
convertaf dw $
numreal real4 1.0
resreal real4 ?
temp REAL4 ?
Resul dd ? ; Variable para el result
Desca dd ? ; Variable para correccion de pila
data Ends
Pilha Segment 'stack'
db 100 dup(?)
pilha ends
Code Segment
Assume CS: Code, DS: data, es:SEG temp
call clescr
call soma
call ajuda
call exit
call erro
call erro2
Inicio: ;beginning of program
mov ax,data ;move data para ax
mov ds,ax ;move ax para ds
mov es,ax ;move ax para es
jmp soma
clescr proc near
mov ah,6
xor cx,cx
mov dx,184fh
mov al,0
mov bh,7
int 10h
clescr endp
mov dx,dx
or dx,dx
mov ah,01h
mov cx,07h
int 10h
lea dx,menu
mov ah,09h
int 21h
mov ah, 1
int 21h
mov cl,al
cmp cl,'1'
jz soma
cmp cl,'2'
jz Ajuda
cmp cl,'3'
jz exit
jnz erro
jmp soma
erro proc near
lea dx,menserro
mov ah,09h
int 21h
lea dx,prima
mov ah,09h
int 21h
mov ah,1
int 21h
jmp inicio
erro endp
Ajuda proc near
Ajuda endp
soma proc near
lea dx,mens1
mov ah,09h
int 21h
mov ah,0ah
lea dx,posinum
int 21h
call convertnum
mov num,bx
xor dx,dx
mov ax,num
mul ax
jnc somaconv
adc dx,0
somaconv:
; call converteascii
; lea dx,mens3
;mov ah,09h
;int 21
;lea dx,result
;mov ah,09h
;int 21h
; lea dx,real
; mov ah,09h
; int 21h
;numreal real4 5.0
;resreal real4 ?
;temp REAL4 ?
finit
fld1;numreal
fmul st,st(0) ;x*x
fldpi
fmul
;fstp resreal
fstp Dword Ptr ds:[Resul]
;fstp Dword Ptr ds:[Desca]
fwait
;mov result,dword ptr resreal
mov bx,ds
call convertenum
mov num,bx
xor dx,dx
mov ax,num
;mov ax,resreal
call converteascii
lea dx,mens3
mov ah,09h
int 21h
lea dx,result
mov ah,09h
int 21h
;Fim area
jmp exit
soma enDP
convertenum proc near
mov dx,0ah
cmp num,0
jnz convertenum1
lea di,posinum + 1
mov cx,[di]
lea si,posinum + 2
jmp convertenum2
convertenum1:
lea di,posinum2 + 1
mov cx,[di]
lea si,posinum2 + 2
convertenum2:
xor ch,ch
lea di,convert
dec si
add si,cx
xor bx,bx
std
convertenum3:
lodsb
cmp al,'0'
jb convertenum4
cmp al,'9'
ja convertenum4
sub al,30h
cbw
mov dx,[di]
mul dx
jc convertenum5
add bx,ax
jc convertenum5
add di,2
loop convertenum3
jmp convertenum6
convertenum4:
jmp convertenum6
convertenum5:
mov num,2
convertenum6:
cld
ret
convertenum endp
converteascii proc near
push dx
push ax
lea si,result
mov cx,10
converteascii1:
pop ax
pop dx
mov bx,ax
mov ax,dx
lea si,result
add si,11
mov cx,10
introdnum:
dec si
xor dx,dx
div cx
mov di,ax
mov ax,bx
div cx
mov bx,ax
mov ax,di
add dl,30h
mov [si],dl
or ax,ax
jnz introdnum
or bx,bx
jnz introdnum
ret
converteascii endp
exit proc near
lea dx,sair
mov ah,09h
int 21h
mov ah,1
int 21h
mov cl,al
cmp cl,'N'
jz inicio
cmp cl,'S'
jz fim
cmp cl,'n'
jz inicio
cmp cl,'s'
jz fim
jnz erro2
exit endp
erro2 proc near
lea dx,menserro2
mov ah,09h
int 21h
lea dx,prima2
mov ah,09h
int 21h
lea dx,nota
mov ah,09h
int 21h
mov ah,1
int 21h
jmp exit
erro2 endp
; process overlow error:
;++++++++++++++++++++++ Getchar +++++++++++++++++++++++++++++++++++++++++++++
getch proc near
xor ax,ax
mov ah,08h
int 21h
ret
getch endp
Fim:
mov ah,4ch
int 21h
Code Ends
End Inicio