Basically I'm trying to make a boolean calculator, which you can use AND, OR, NOT, and XOR with. The user makes thier choice of what to do, they input the appropriate number of arguments, and then the result is displayed. However, the result is rarely correct. I have on idea what is causing it, so I could really use your help :).
TITLE Simple Boolean Calculator (BoolCalc.asm)
; *** NOT WORKING PROPERLY ***
; Program Description: A simple boolean calculator with a menu.
; Author: BBG
; Creation Date: Feb 13 2005
; Revisions:
; Date: Modified By:
INCLUDE Irvine32.inc
.data
menu BYTE "1. x AND y",0Dh,0Ah, ; The menu to display
"2. x OR y",0Dh,0Ah,
"3. NOT x",0Dh,0Ah,
"4. x XOR y",0Dh,0Ah,
"5. Exit program",0
choice BYTE "What is your choice? ",0
prompt1 BYTE "Enter the first value: ",0
prompt2 BYTE "Enter the second value: ",0
result BYTE "The result is: ",0
value1 DWORD ?
value2 DWORD ?
.code
main PROC
mov edx, OFFSET menu
call WriteString ; Just writes the value of menu to the screen
call Crlf ; Next line
call Crlf
mov edx, OFFSET choice
call WriteString ; Prompt user for their choice
call ReadInt ; Read their choice
mov ebx,eax ; Their choice is stored in eax with ReadInt, so move to ebx
cmp ebx,5
je quit ; If their choice is 5 just quit
mov edx,OFFSET prompt1
call WriteString ; Prompt for first value
call ReadHex ; Read in the hex value
mov value1,eax
cmp ebx,3 ; If choice is 3 (NOT), skip second prompt
je L3
mov edx,OFFSET prompt2 ; Prompt for second hex value
call WriteString
call ReadHex
mov value2,eax
start: ; Find out where to go
cmp ebx,1
je L1
cmp ebx,2
je L2
cmp ebx,4
je L4
L1: mov eax,value1 ; logical AND
and eax,value2
jmp display
L2: mov eax,value1 ; logical OR
or eax,value2
jmp display
L3: mov eax,value1 ; logical NOT
not eax
jmp display
L4: mov eax,value1 ; logical XOR
xor eax,value2
jmp display
display:
mov edx,OFFSET result ; Write result string
call WriteString
call WriteHex ; Value to write stored in eax, output it
call Crlf ; next line
quit:
exit
main ENDP
END main
Below are some sample outputs:
Quote:1. x AND y
2. x OR y
3. NOT x
4. x XOR y
5. Exit program
What is your choice? 1
Enter the first value: f0f0f0f0
Enter the second value: ffffffff
The result is: F0F0F000
Press any key to continue . . .
Quote:1. x AND y
2. x OR y
3. NOT x
4. x XOR y
5. Exit program
What is your choice? 2
Enter the first value: f0f0f0f0
Enter the second value: ff00ff00
The result is: F0FFF000
Press any key to continue . . .
Quote:1. x AND y
2. x OR y
3. NOT x
4. x XOR y
5. Exit program
What is your choice? 3
Enter the first value: f0f0f0f0
The result is: 0F0F0FFF
Press any key to continue . . .
Quote:1. x AND y
2. x OR y
3. NOT x
4. x XOR y
5. Exit program
What is your choice? 4
Enter the first value: f0f0f0f0
Enter the second value: f00f00f0
The result is: FFF00000
Press any key to continue . . .
It almost seems as if the result has been shifted left one byte... but why?!?!
Please help :-(
[Edited by - Nietsnie on February 13, 2005 1:09:16 AM]