Help Me to Create A Hexadecimal Calculator.

I and my friend write code for a hexadecimal calculator.
Example of result that display on monitor.

Enter a hexadecimal Expression : 1B+2-1
Output Result : 1C

But I have a problem with in using gotten input value from keyboard.
The program gets an input value like a string.I want to check each character.Is it a 0-9,A-F or + - * /?When Program check character already then check next chracter in input string value.but I don't know how to do it. [color=Red][size=3]please help me hurry.I have to finished it in 1 week[/size].[/color]

1.the first numbers(in string) convert to hex and move to val1
2.math operation sign move to val2
3.the second and after numbers convert to hex and move to val2

[color=Blue]This my code[/color]

TITLE Hexadecimal Calculator
INCLUDE Irvine32.inc

.data
input byte "Enter a hexadecimal expression : ", 0dh, 0ah, 0
output byte "The output is : ", 0dh, 0ah, 0
overflow byte "It is an overflow.", 0dh, 0ah, 0
error byte "It is an invalid input.", 0dh, 0ah, 0
ex byte 5 DUP(0)
excount dword ?
val1 dword ?
opera dword ?
val2 dword ?

.code
main PROC

operand1: call Clrscr
mov edx, OFFSET input
call WriteString
mov edx, OFFSET ex
mov ecx, SIZEOF ex
call ReadString
mov excount, eax
.IF edx >= 30h && edx <= 39h
sub edx, 30h
shld eax, edx, 4
.ELSEIF edx >= 41h && edx <= 46h
sub edx, 37h
shld eax, edx, 4
.ELSEIF edx >= 61h && edx <= 66h
sub edx, 57h
shld eax, edx, 4
.ELSE
mov edx, OFFSET error
call WriteString
.ENDIF
mov ecx,excount
L1 : .IF edx >= 30h && edx <= 39h
sub edx, 30h
shld eax, edx, 4
.ELSEIF edx >= 41h && edx <= 46h
sub edx, 37h
shld eax, edx, 4
.ELSEIF edx >= 61h && edx <= 66h
sub edx, 57h
shld eax, edx, 4
.ELSEIF edx == '+' || edx == '-' || edx == '*' || edx == '/'
jmp op
.ELSE
mov edx, OFFSET error
call WriteString
.ENDIF
LOOP L1
op : mov val1, eax
mov eax, 0
mov opera, edx
L2 : .IF edx >= 30h && edx <= 39h
sub edx, 30h
shld eax, edx, 4
.ELSEIF edx >= 41h && edx <= 46h
sub edx, 37h
shld eax, edx, 4
.ELSEIF edx >= 61h && edx <= 66h
sub edx, 57h
shld eax, edx, 4
.ELSE
mov edx, OFFSET error
call WriteString
.ENDIF
L3 : .IF edx >= 30h && edx <= 39h
sub edx, 30h
shld eax, edx, 4
.ELSEIF edx >= 41h && edx <= 46h
sub edx, 37h
shld eax, edx, 4
.ELSEIF edx >= 61h && edx <= 66h
sub edx, 57h
shld eax, edx, 4
.ELSEIF edx == '+' || edx == '-' || edx == '*' || edx == '/'
jmp op2
.ELSEIF ecx == 0
jmp finish
.ELSE
mov edx, OFFSET error
call WriteString
.ENDIF
LOOP L3
op2 : mov val2, eax
mov eax, 0
mov ebx, opera
.IF ebx == '+'
mov eax, val1
add eax, val2
mov val1, eax
.ELSEIF ebx == '-'
mov eax, val1
sub eax, val2
mov val1, eax
.ELSEIF ebx == '*'
mov eax, val1
mul val2
mov val1, eax
.ELSEIF ebx == '/'
mov eax, val1
div val2
mov val1, ebx

.ENDIF
mov opera, edx
jmp L2
finish : mov val2, eax
mov ebx, opera
.IF ebx == '+'
mov eax, val1
add eax, val2
mov val1, eax
jmp result
.ELSEIF ebx == '-'
mov eax, val1
sub eax, val2
mov val1, eax
jmp result
.ELSEIF ebx == '*'
mov eax, val1
mul val2
mov val1, eax
jmp result
.ELSEIF ebx == '/'
mov eax, val1
div val2
mov val1, ebx
jmp result
.ENDIF
overmsg : mov edx, OFFSET overflow
call WriteString
jmp operand1
result : mov edx, OFFSET output
call WriteString
mov eax, val1
call WriteHex

exit
main ENDP
END main
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories