I am trying to build an program in the assembly language (.jas). The program that I want to build gets some input like: 333450. That input is stored into a variable. Than there is some output. (You can see the code below). But now I want the program to read the first digit of the number above (so, i want the 3 from 333450). How do I get the first 3? I am pretty new with assembly so any tips are welcome.
I thought something like an array, but I don't think it is possible in assembly. So there has to be another way to do it. After a little research I fount out this: Reading a number using INT 21h (DOS) & 8086 assmebly But there seems to be a problem with that. I dont have all the commands that are used in that example. Is there anything else I can do? Maybe it is possible with some bitshift? I've read something about bitshifts that it can change your number to something else.
Is it possible to read the number in a 16bit 2 complement representation and read each bit individual to get the numbers?
It is for a MIC1 simulator.
CODE:
.constant
OBJREF 0x40 // Needed for method invokation
.end-constant
.main // Start of main program
.var // Local variables for main program
counter
number
last
.end-var
start: ISTORE counter // Initialize variables
ISTORE number
ISTORE last
BIPUSH 0x49 // Print "UITVOER:"
OUT
BIPUSH 0x4E
OUT
BIPUSH 0x56
OUT
BIPUSH 0x4F
OUT
BIPUSH 0x45
OUT
BIPUSH 0x52
OUT
BIPUSH 0x3A
OUT
BIPUSH 0x20
OUT
LDC_W OBJREF // Prepare for a method call
INVOKEVIRTUAL getnumber
ISTORE number // Store return value in number
OUT
.end-main // End of main program
.method getnumber()
.var
number
.end-var
BIPUSH 0x0
ISTORE number
get: IN // Read a key press
DUP // Duplicate key for comparison
BIPUSH 0xa // If key = pressed,
IF_ICMPEQ return // Return
DUP
BIPUSH 0x30 // If key < "0"
ISUB
IFLT geta2 // Goto geta2 (key is not a hex digit)
DUP
BIPUSH 0x3a // Else if key < ":"
ISUB
IFLT geta1 // Goto geta1 (key is numeric character - "0"-"9")
DUP
BIPUSH 0x3A // Else if key > ":"
SWAP
ISUB
IFLT geta2 // Goto geta2 (key is not a hex digit)
get1: DUP
OUT // Print key (numeric character)
BIPUSH 0x30 // Convert key from character to number
ISUB
get2: POP // Pop invalid character
GOTO get // Get next key
return: OUT // Print cr
ILOAD number // Load a as return value
IRETURN // Return
.end-method