Click to See Complete Forum and Search --> : Pep/8: trouble working with and outputting hex


zapman2003
April 28th, 2009, 04:45 PM
Hello,
I've had trouble with an assignment. The purpose of the program is to take two hardcoded hex values, output them as a string, and perform an exor operation and output the result in hex also.

Example run of program
Given:
MLB: .equate 8 ; multi-length bytes
A: .word 0x0123
.word 0xABCD
.word 0x5678
.word 0xCDEF
B: .word 0x0010
.word 0xaaaa
.word 0x8765
.word 0x2323
Program output is
0123abcd5678cdef
exor 0010aaaa87652323
= 01330167d11deecc

The code I have written to output the hex is:
hex: ldx 0,i
ldbytea A,d
top: cpx MLB,i
brge endit
asla
asla
asla
asla
stbytea -2,s
anda 0xF,i
charo A,x
ldbytea -2,s
addx 1,i
br top
endit: stop

It works fine when outputting a basic string, such as ascii: "0123456789abcdef", but only outputs garbage when applied to a hex number. I am severely stumped as to how to proceed, as I can only assume it's outputting ascii codes as opposed to the actual hex value and I don't know how to get it to output correctly. Any help would be much appreciated!

guitarlady3000
April 30th, 2009, 08:06 PM
Hey, i think you're in the same class as me....well i looked around and i found this outline for the 3 subroutines we should use


HEXO: Takes a word parameter N and outputs it in hex. It
makes use of SHIFT and HEXDIG defined below

SHIFT : Takes word parameters N and X and returns a word as its result
If X ≥ 0 returns N rotated X places left
If X < 0 returns N rotated -X places right
So the sign of X tells you which way to shift and the absolute value of X
tells you how many places to shift. This routine will help you to isolate
individual nybbles (4-bit groups) of the number to be output.

HEXDIG: Takes a byte parameter containing a value in the range 0..15 and outputs the appropriate hexadecimal digit.

I'm not sure sure about the shifting deal, in this one though....


Numbers 0-9 are represented as numbers as a hexdigit and from 10-15 is A through F...i have no dang clue to get each hexdigit for A and B, but i know they are each represented by a certain binary number, four bits per hexdigit.

So im totally lost too haha