I'm making a program to add two floating point numbers using ASCII operations AAA and AAS. I've run into the problem of aligning the decimal point for the two numbers. So I decided to split the floating point number into two halfs. The Whole number part and the Decimal part.
For example, the two numbers: 123.456 and 22.35 would be saved in the variables....
123 -> FPNum_W1
456 ->FPNum_D1
22 ->FPNum_W2
35 ->FPNum_D2
Then I would add the two parts seperately and put it back together to print the sum. Any how... I'm having some trouble w/ my code. I can't get the floating point number split in two and saved in seperate varaibles. I need some assistance. This is what I got so far.
;===============================================
INCLUDE Irvine32.inc
.data
str1 BYTE "Assignment4: Addition of two Floating Point Numbers ",0Ah, 0Dh, 0
str2 BYTE "Enter your name: ", 0
str3 BYTE "Please enter two Floating Point Numbers, ",0
str4 BYTE "Enter first Floating Point Number: ", 0
str5 BYTE "Enter second Floating Point Number: ", 0
str6 BYTE "Continue? (y/n): ", 0
char BYTE ?
buffer BYTE 50 dup (0)
FPVal1 BYTE 50 dup ('0')
FPVal2 BYTE 50 dup ('0')
FPSum1 BYTE 50 dup ('0')
FPVal_W1 BYTE 50 dup ('0')
FPVal_D1 BYTE 50 dup ('0')
FPVal_W2 BYTE 50 dup ('0')
FPVal_D2 BYTE 50 dup ('0')
FPSum_W1 BYTE 60 dup ('0')
FPSum_D1 BYTE 60 dup ('0')
setPointer MACRO reg, var ; Macro to set pointer
lea reg, var ; Load Effective Address of register
add reg, lengthof var ; Move pointer to end of string
dec reg ; Move back one
ENDM ; End of Macro definition
EnterString MACRO FP_Buffer ; Readstring Macro
lea edx, FP_Buffer ; Load Effective Address of FP_Buffer
mov ecx, (SIZEOF FP_Buffer) - 1 ; Maximum number of characters
call Readstring ; Call Readstring function
ENDM
.code
main PROC
mov eax, lightGreen + (black * 16) ;light green text on black background
call SetTextColor
call Clrscr
lea edx, str1 ; load effective address str1
call WriteString ; "Assignment4: Addition of two Floating Point Numbers"
call Crlf ; end line
call WaitMsg ; "Press..."
lea edx, str2 ; load effective offset str2
call WriteString ; "Enter your name: "
lea edx, buffer ; load effective address buffer
mov ecx, (SIZEOF buffer) - 1 ; maximum # of characters
call ReadString ; read string input from user
lea edx, str3 ; load effective address str3
call WriteString ; "Please enter two Floating Point Numbers, "
lea edx, buffer ; load effective offset buffer
call WriteString ; display user name
call Crlf ; end line
Again:
call Crlf
lea edx, str4 ; load effective address str4
call WriteString ; "Enter first Floating Point Number: "
Enterstring FPVal1 ; read floating point value from user
call Crlf ; end line
lea edx, str5 ; load effective offset str5
call WriteString ; "Enter second Floating Point Number: "
Enterstring FPVal2 ; read floating point value from user
call Crlf ; end line
Check_Length:
lea esi, FPVal1
lea edi, FPVal1
mov al, lengthof FPVal1
mov ah, lengthof FPVal2
cmp al, ah
jge Mov_Val1
Mov_Val1:
cmp byte ptr , '.'
je Mov_Right_Side1
inc esi
jmp Mov_Val1
Mov_Right_Side1:
L1:
cmpsb
je Done
dec esi
mov bl,
mov FPVal_W1, bl
jmp L1
comment % ;comment out from here
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side1
Mov_Val2:
cmp byte ptr , '.'
je Mov_Right_Side2
xor eax, eax
mov eax,
mov FPVal_W1, edx
inc edi
jmp Mov_Val2
Mov_Right_Side2:
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side2
to here
%
Done:
lea edx, FPVal1
call Writestring
call Crlf
lea edx, FPVal2
call Writestring
call Crlf
lea edx, FPVal_W1
call Writestring
call Crlf
lea edx, str4 ; load effective offset str4
call WriteString ; "Continue? (y/n): "
call ReadChar ; read character input from user
xor al, al ; clear al register
mov char, al ; copy answer to variable
.IF (char == 'y') || (char == 'Y') ; if answer is yes
jmp Again ; jump back to Again
.ENDIF
exit
main ENDP
END main
For example, the two numbers: 123.456 and 22.35 would be saved in the variables....
123 -> FPNum_W1
456 ->FPNum_D1
22 ->FPNum_W2
35 ->FPNum_D2
Then I would add the two parts seperately and put it back together to print the sum. Any how... I'm having some trouble w/ my code. I can't get the floating point number split in two and saved in seperate varaibles. I need some assistance. This is what I got so far.
;===============================================
INCLUDE Irvine32.inc
.data
str1 BYTE "Assignment4: Addition of two Floating Point Numbers ",0Ah, 0Dh, 0
str2 BYTE "Enter your name: ", 0
str3 BYTE "Please enter two Floating Point Numbers, ",0
str4 BYTE "Enter first Floating Point Number: ", 0
str5 BYTE "Enter second Floating Point Number: ", 0
str6 BYTE "Continue? (y/n): ", 0
char BYTE ?
buffer BYTE 50 dup (0)
FPVal1 BYTE 50 dup ('0')
FPVal2 BYTE 50 dup ('0')
FPSum1 BYTE 50 dup ('0')
FPVal_W1 BYTE 50 dup ('0')
FPVal_D1 BYTE 50 dup ('0')
FPVal_W2 BYTE 50 dup ('0')
FPVal_D2 BYTE 50 dup ('0')
FPSum_W1 BYTE 60 dup ('0')
FPSum_D1 BYTE 60 dup ('0')
setPointer MACRO reg, var ; Macro to set pointer
lea reg, var ; Load Effective Address of register
add reg, lengthof var ; Move pointer to end of string
dec reg ; Move back one
ENDM ; End of Macro definition
EnterString MACRO FP_Buffer ; Readstring Macro
lea edx, FP_Buffer ; Load Effective Address of FP_Buffer
mov ecx, (SIZEOF FP_Buffer) - 1 ; Maximum number of characters
call Readstring ; Call Readstring function
ENDM
.code
main PROC
mov eax, lightGreen + (black * 16) ;light green text on black background
call SetTextColor
call Clrscr
lea edx, str1 ; load effective address str1
call WriteString ; "Assignment4: Addition of two Floating Point Numbers"
call Crlf ; end line
call WaitMsg ; "Press..."
lea edx, str2 ; load effective offset str2
call WriteString ; "Enter your name: "
lea edx, buffer ; load effective address buffer
mov ecx, (SIZEOF buffer) - 1 ; maximum # of characters
call ReadString ; read string input from user
lea edx, str3 ; load effective address str3
call WriteString ; "Please enter two Floating Point Numbers, "
lea edx, buffer ; load effective offset buffer
call WriteString ; display user name
call Crlf ; end line
Again:
call Crlf
lea edx, str4 ; load effective address str4
call WriteString ; "Enter first Floating Point Number: "
Enterstring FPVal1 ; read floating point value from user
call Crlf ; end line
lea edx, str5 ; load effective offset str5
call WriteString ; "Enter second Floating Point Number: "
Enterstring FPVal2 ; read floating point value from user
call Crlf ; end line
Check_Length:
lea esi, FPVal1
lea edi, FPVal1
mov al, lengthof FPVal1
mov ah, lengthof FPVal2
cmp al, ah
jge Mov_Val1
Mov_Val1:
cmp byte ptr , '.'
je Mov_Right_Side1
inc esi
jmp Mov_Val1
Mov_Right_Side1:
L1:
cmpsb
je Done
dec esi
mov bl,
mov FPVal_W1, bl
jmp L1
comment % ;comment out from here
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side1
Mov_Val2:
cmp byte ptr , '.'
je Mov_Right_Side2
xor eax, eax
mov eax,
mov FPVal_W1, edx
inc edi
jmp Mov_Val2
Mov_Right_Side2:
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side2
to here
%
Done:
lea edx, FPVal1
call Writestring
call Crlf
lea edx, FPVal2
call Writestring
call Crlf
lea edx, FPVal_W1
call Writestring
call Crlf
lea edx, str4 ; load effective offset str4
call WriteString ; "Continue? (y/n): "
call ReadChar ; read character input from user
xor al, al ; clear al register
mov char, al ; copy answer to variable
.IF (char == 'y') || (char == 'Y') ; if answer is yes
jmp Again ; jump back to Again
.ENDIF
exit
main ENDP
END main
;===============================================
INCLUDE Irvine32.inc
.data
str1 BYTE "Assignment4: Addition of two Floating Point Numbers ",0Ah, 0Dh, 0
str2 BYTE "Enter your name: ", 0
str3 BYTE "Please enter two Floating Point Numbers, ",0
str4 BYTE "Enter first Floating Point Number: ", 0
str5 BYTE "Enter second Floating Point Number: ", 0
str6 BYTE "Continue? (y/n): ", 0
char BYTE ?
buffer BYTE 50 dup (0)
FPVal1 BYTE 50 dup ('0')
FPVal2 BYTE 50 dup ('0')
FPSum1 BYTE 50 dup ('0')
FPVal_W1 BYTE 50 dup ('0')
FPVal_D1 BYTE 50 dup ('0')
FPVal_W2 BYTE 50 dup ('0')
FPVal_D2 BYTE 50 dup ('0')
FPSum_W1 BYTE 60 dup ('0')
FPSum_D1 BYTE 60 dup ('0')
setPointer MACRO reg, var ; Macro to set pointer
lea reg, var ; Load Effective Address of register
add reg, lengthof var ; Move pointer to end of string
dec reg ; Move back one
ENDM ; End of Macro definition
EnterString MACRO FP_Buffer ; Readstring Macro
lea edx, FP_Buffer ; Load Effective Address of FP_Buffer
mov ecx, (SIZEOF FP_Buffer) - 1 ; Maximum number of characters
call Readstring ; Call Readstring function
ENDM
.code
main PROC
mov eax, lightGreen + (black * 16) ;light green text on black background
call SetTextColor
call Clrscr
lea edx, str1 ; load effective address str1
call WriteString ; "Assignment4: Addition of two Floating Point Numbers"
call Crlf ; end line
call WaitMsg ; "Press..."
lea edx, str2 ; load effective offset str2
call WriteString ; "Enter your name: "
lea edx, buffer ; load effective address buffer
mov ecx, (SIZEOF buffer) - 1 ; maximum # of characters
call ReadString ; read string input from user
lea edx, str3 ; load effective address str3
call WriteString ; "Please enter two Floating Point Numbers, "
lea edx, buffer ; load effective offset buffer
call WriteString ; display user name
call Crlf ; end line
Again:
call Crlf
lea edx, str4 ; load effective address str4
call WriteString ; "Enter first Floating Point Number: "
Enterstring FPVal1 ; read floating point value from user
call Crlf ; end line
lea edx, str5 ; load effective offset str5
call WriteString ; "Enter second Floating Point Number: "
Enterstring FPVal2 ; read floating point value from user
call Crlf ; end line
Check_Length:
lea esi, FPVal1
lea edi, FPVal1
mov al, lengthof FPVal1
mov ah, lengthof FPVal2
cmp al, ah
jge Mov_Val1
Mov_Val1:
cmp byte ptr , '.'
je Mov_Right_Side1
inc esi
jmp Mov_Val1
Mov_Right_Side1:
L1:
cmpsb
je Done
dec esi
mov bl,
mov FPVal_W1, bl
jmp L1
comment % ;comment out from here
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side1
Mov_Val2:
cmp byte ptr , '.'
je Mov_Right_Side2
xor eax, eax
mov eax,
mov FPVal_W1, edx
inc edi
jmp Mov_Val2
Mov_Right_Side2:
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side2
to here
%
Done:
lea edx, FPVal1
call Writestring
call Crlf
lea edx, FPVal2
call Writestring
call Crlf
lea edx, FPVal_W1
call Writestring
call Crlf
lea edx, str4 ; load effective offset str4
call WriteString ; "Continue? (y/n): "
call ReadChar ; read character input from user
xor al, al ; clear al register
mov char, al ; copy answer to variable
.IF (char == 'y') || (char == 'Y') ; if answer is yes
jmp Again ; jump back to Again
.ENDIF
exit
main ENDP
END main
:stupid: sorry about that
;===============================================
INCLUDE Irvine32.inc
.data
str1 BYTE "Assignment4: Addition of two Floating Point Numbers ",0Ah, 0Dh, 0
str2 BYTE "Enter your name: ", 0
str3 BYTE "Please enter two Floating Point Numbers, ",0
str4 BYTE "Enter first Floating Point Number: ", 0
str5 BYTE "Enter second Floating Point Number: ", 0
str6 BYTE "Continue? (y/n): ", 0
char BYTE ?
buffer BYTE 50 dup (0)
FPVal1 BYTE 50 dup ('0')
FPVal2 BYTE 50 dup ('0')
FPSum1 BYTE 50 dup ('0')
FPVal_W1 BYTE 50 dup ('0')
FPVal_D1 BYTE 50 dup ('0')
FPVal_W2 BYTE 50 dup ('0')
FPVal_D2 BYTE 50 dup ('0')
FPSum_W1 BYTE 60 dup ('0')
FPSum_D1 BYTE 60 dup ('0')
setPointer MACRO reg, var ; Macro to set pointer
lea reg, var ; Load Effective Address of register
add reg, lengthof var ; Move pointer to end of string
dec reg ; Move back one
ENDM ; End of Macro definition
EnterString MACRO FP_Buffer ; Readstring Macro
lea edx, FP_Buffer ; Load Effective Address of FP_Buffer
mov ecx, (SIZEOF FP_Buffer) - 1 ; Maximum number of characters
call Readstring ; Call Readstring function
ENDM
.code
main PROC
mov eax, lightGreen + (black * 16) ;light green text on black background
call SetTextColor
call Clrscr
lea edx, str1 ; load effective address str1
call WriteString ; "Assignment4: Addition of two Floating Point Numbers"
call Crlf ; end line
call WaitMsg ; "Press..."
lea edx, str2 ; load effective offset str2
call WriteString ; "Enter your name: "
lea edx, buffer ; load effective address buffer
mov ecx, (SIZEOF buffer) - 1 ; maximum # of characters
call ReadString ; read string input from user
lea edx, str3 ; load effective address str3
call WriteString ; "Please enter two Floating Point Numbers, "
lea edx, buffer ; load effective offset buffer
call WriteString ; display user name
call Crlf ; end line
Again:
call Crlf
lea edx, str4 ; load effective address str4
call WriteString ; "Enter first Floating Point Number: "
Enterstring FPVal1 ; read floating point value from user
call Crlf ; end line
lea edx, str5 ; load effective offset str5
call WriteString ; "Enter second Floating Point Number: "
Enterstring FPVal2 ; read floating point value from user
call Crlf ; end line
Check_Length:
lea esi, FPVal1
lea edi, FPVal1
mov al, lengthof FPVal1
mov ah, lengthof FPVal2
cmp al, ah
jge Mov_Val1
Mov_Val1:
cmp byte ptr , '.'
je Mov_Right_Side1
inc esi
jmp Mov_Val1
Mov_Right_Side1:
L1:
cmpsb
je Done
dec esi
mov bl,
mov FPVal_W1, bl
jmp L1
comment % ;comment out from here
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side1
Mov_Val2:
cmp byte ptr , '.'
je Mov_Right_Side2
xor eax, eax
mov eax,
mov FPVal_W1, edx
inc edi
jmp Mov_Val2
Mov_Right_Side2:
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side2
to here
%
Done:
lea edx, FPVal1
call Writestring
call Crlf
lea edx, FPVal2
call Writestring
call Crlf
lea edx, FPVal_W1
call Writestring
call Crlf
lea edx, str4 ; load effective offset str4
call WriteString ; "Continue? (y/n): "
call ReadChar ; read character input from user
xor al, al ; clear al register
mov char, al ; copy answer to variable
.IF (char == 'y') || (char == 'Y') ; if answer is yes
jmp Again ; jump back to Again
.ENDIF
exit
main ENDP
END main
;===============================================
INCLUDE Irvine32.inc
.data
str1 BYTE "Assignment4: Addition of two Floating Point Numbers ",0Ah, 0Dh, 0
str2 BYTE "Enter your name: ", 0
str3 BYTE "Please enter two Floating Point Numbers, ",0
str4 BYTE "Enter first Floating Point Number: ", 0
str5 BYTE "Enter second Floating Point Number: ", 0
str6 BYTE "Continue? (y/n): ", 0
char BYTE ?
buffer BYTE 50 dup (0)
FPVal1 BYTE 50 dup ('0')
FPVal2 BYTE 50 dup ('0')
FPSum1 BYTE 50 dup ('0')
FPVal_W1 BYTE 50 dup ('0')
FPVal_D1 BYTE 50 dup ('0')
FPVal_W2 BYTE 50 dup ('0')
FPVal_D2 BYTE 50 dup ('0')
FPSum_W1 BYTE 60 dup ('0')
FPSum_D1 BYTE 60 dup ('0')
setPointer MACRO reg, var ; Macro to set pointer
lea reg, var ; Load Effective Address of register
add reg, lengthof var ; Move pointer to end of string
dec reg ; Move back one
ENDM ; End of Macro definition
EnterString MACRO FP_Buffer ; Readstring Macro
lea edx, FP_Buffer ; Load Effective Address of FP_Buffer
mov ecx, (SIZEOF FP_Buffer) - 1 ; Maximum number of characters
call Readstring ; Call Readstring function
ENDM
.code
main PROC
mov eax, lightGreen + (black * 16) ;light green text on black background
call SetTextColor
call Clrscr
lea edx, str1 ; load effective address str1
call WriteString ; "Assignment4: Addition of two Floating Point Numbers"
call Crlf ; end line
call WaitMsg ; "Press..."
lea edx, str2 ; load effective offset str2
call WriteString ; "Enter your name: "
lea edx, buffer ; load effective address buffer
mov ecx, (SIZEOF buffer) - 1 ; maximum # of characters
call ReadString ; read string input from user
lea edx, str3 ; load effective address str3
call WriteString ; "Please enter two Floating Point Numbers, "
lea edx, buffer ; load effective offset buffer
call WriteString ; display user name
call Crlf ; end line
Again:
call Crlf
lea edx, str4 ; load effective address str4
call WriteString ; "Enter first Floating Point Number: "
Enterstring FPVal1 ; read floating point value from user
call Crlf ; end line
lea edx, str5 ; load effective offset str5
call WriteString ; "Enter second Floating Point Number: "
Enterstring FPVal2 ; read floating point value from user
call Crlf ; end line
Check_Length:
lea esi, FPVal1
lea edi, FPVal1
mov al, lengthof FPVal1
mov ah, lengthof FPVal2
cmp al, ah
jge Mov_Val1
Mov_Val1:
cmp byte ptr , '.'
je Mov_Right_Side1
inc esi
jmp Mov_Val1
Mov_Right_Side1:
L1:
cmpsb
je Done
dec esi
mov bl,
mov FPVal_W1, bl
jmp L1
comment % ;comment out from here
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side1
Mov_Val2:
cmp byte ptr , '.'
je Mov_Right_Side2
xor eax, eax
mov eax,
mov FPVal_W1, edx
inc edi
jmp Mov_Val2
Mov_Right_Side2:
.IF ( (byte ptr == 0Ah) ||(byte ptr == 0Dh) )
jmp Done
.ENDIF
inc esi
xor eax, eax
mov eax,
mov FPVal_D1, eax
jmp Mov_Right_Side2
to here
%
Done:
lea edx, FPVal1
call Writestring
call Crlf
lea edx, FPVal2
call Writestring
call Crlf
lea edx, FPVal_W1
call Writestring
call Crlf
lea edx, str4 ; load effective offset str4
call WriteString ; "Continue? (y/n): "
call ReadChar ; read character input from user
xor al, al ; clear al register
mov char, al ; copy answer to variable
.IF (char == 'y') || (char == 'Y') ; if answer is yes
jmp Again ; jump back to Again
.ENDIF
exit
main ENDP
END main
:confused:
If you want to add two floating point numbers use the FPU.
But your usage here looks more like fixed-point numbers.
If you want to add two floating point numbers use the FPU.
But your usage here looks more like fixed-point numbers.
You can also EDIT your post, no need to post 3 times.
well this an assignment to teach us to use ascii operations... so I have to use this method. I'm just having some problem splitting up the number into 2 parts. I have the actual use of the aaa and aas command down. I'm not sure what the problem is, but for example if someone enters: 123.456
Instead of saving it like this: 1230000000000000000 -> FPVal_W1 and 000000000000456 ->FPVal_D1
I get: 12300000000000000000456 -> FPVal_W1 and 0000000000000000000456 -> FPVal_D1
Don't know where the 456 is coming from in FPVal_W1
Instead of saving it like this: 1230000000000000000 -> FPVal_W1 and 000000000000456 ->FPVal_D1
I get: 12300000000000000000456 -> FPVal_W1 and 0000000000000000000456 -> FPVal_D1
Don't know where the 456 is coming from in FPVal_W1