开发者

output byte value in assembler

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 ove开发者_开发问答r99Label
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 :)


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

Convert the value to a string representation and print it.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜