necrojb 0 Newbie Poster

Hey guys, it's been a while since i've had to do any assembly programming but it's come up again in a course of mine to haunt me :p

We're trying to simulate reverse polish notation, which is fairly simple..and all we have to implement is addition/subtraction, with a few other conditions such as exiting when an X is input, and displaying an E when anything other then X, +, - , 0-9 is input.

My issue is coming up now that I have my IJVM code working for addition and subtraction, but for numbers higher then 10 which obviously is when the separation between decimal and hex begins.

I need a helping hand getting the logic behind outputting the correct values in DECIMAL, and not hex.

What I have so far is this -

.constant
OBJREF 0x40			// needed for method invokation - see S.C.O. chapter 4
.end-constant


.main				// start of program

.var				// local variables for main program
.end-var

start:
	LDC_W OBJREF		// prepare for method call
	INVOKEVIRTUAL getnum
	GOTO start
	
	
.end-main

.method getnum()
.var
.end-var

geta:	IN			// read key press
	DUP			// duplicate key for comparison
	BIPUSH 0x0
	IF_ICMPEQ geta
	DUP
	BIPUSH 0x2b
	IF_ICMPEQ add
	DUP
	BIPUSH 0x2d
	IF_ICMPEQ sub
	DUP
	BIPUSH 0x58
	IF_ICMPEQ return
	DUP
	BIPUSH 0x30
	ISUB
	IFLT error
	DUP
	BIPUSH 0x3a
	SWAP
	ISUB
	IFLT error
//
	BIPUSH 0x30
	ISUB
	GOTO geta
error:	POP
	BIPUSH 0x45
	OUT
	GOTO geta
add:
	POP
	IADD
	DUP
	BIPUSH 0x30
	IADD
	OUT
	GOTO return2
sub:
	POP
	ISUB
	DUP
	BIPUSH 0x30
	IADD
	OUT
	GOTO return2
return: DUP
	OUT
	IRETURN
return2:
	IRETURN	
.end-method
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.