I need a way to make sure that input (4 digits) is in hex format. As long as you input hex, everything works fine, but if you enter a q or s or something it blows up.
The input is stored as an unsigned short int (required), so I can't store them as a string and then loop through and use isxdigit().
Thanks
I Just used:
cin >> hex >> variable_name
to input the hex digits into an unsigned short.
It will end up being an interactive disassembler for a little simulator called H1 that came with our book(Assembly language and computer architecture using C++ and Java). It has a limited instruction set.
All we have to do in this first assignment is prompt for a machine instruction and then display the disassembled instruction, like this:
?4000
Op Code:4 Address field:000
?1e25
Op Code:1 Address field:e25
?ffff
Op Code:ffff Address field:
Most H1 instructions use a 4bit(single hex digit)op-code and a 12 bit(3 hex digit)address field. Next week we will probably have to add the ones that use 8 and 12 bit instructions, but for this assignment all we had to concern ourselves with one exception (ffff-HALT).
Here is the whole thing. Using structs and a union were a requirement. It works perfectly as long as the input is a 4 digit valid hex number.