tags:

views:

130

answers:

2

I'm a bit ashamed about asking this, but how do i output the value of a byte in assembler? Suppose I have the number 62 in the AL register. I'm targeting an 8086. There seem to be available only interrupts that output it's ascii value.

Edit: Thank you Nick D, that was what i was looking for. To answer a couple of questions, i'm actually using an emulator, emu8086. The code will be used in a tiny application in a factory that uses outdated equipment (i.e. it's a secret).

The solution, using Nick D's idea, looks somewhat like this:

compare number, 99
jump if greater to over99Label
compare number, 9
jump if greater to between9and99Label

;if jumps failed, number has one digit
printdigit(number)

between9and99Label:
divide the number by 10
printascii(quotient)
printascii(modulus)
jump to the end

over99Label:
divide the number by 100
printascii(quotient)
store the modulus in the place that between9and99Label sees as input
jump to between9and99Label

the end:
return

and it works fine for unsigned bytes :)

+2  A: 
// pseudocode for values < 100
printAscii (AL div 10) + 48
printAscii (AL mod 10) + 48

Convert the value to a string representation and print it.

Nick D
+1  A: 

I don't have access to an assembler at the momment to check it, and syntax will vary anyway depending on what assembler you are using, but this should still convey the idea.

FOUR_BITS:
.db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'

; If ebx need to be preserved do so
push  ebx

; Get the top four bits of al
mov   bl, al
shl   bl, 4

; Convert that into the ASCII hex representation
mov   bl, [FOUR_BITS + bl]

; Use that value as a parameter to your printing routine
push  bl
call  printAscii
pop   bl

; Get the bottom four bits of al
mov   bl, al
and   bl, 0xF

; Convert that into the ASCII hex representation
mov   bl, [FOUR_BITS + bl]

; Use that value as a parameter to your printing routine
push  bl
call  printAscii
pop   bl

torak
sorry, this doesn't work. suppose i want to print the number 123?
altvali
This prints out the value of the AL register in hexadecimal (see http://en.wikipedia.org/wiki/Hexadecimal). The decimal number 123 is equivalent to the hexadecimal number 7B (aka 0x7B), which is what this code is intended to produce.
torak
ok, thumbs up then, but i wanted a decimal representation, that's why i dismissed your code when i saw you're breaking the byte and only printing two characters.
altvali