Tuesday, April 5, 2011

How to print a word (two bytes) in assembly

assume the data that need to be printed are in DX register. CX(CL) is the counter to be used to shift the bit of DX. At the end of the code, ascii 13 + ascii 10 are equivalent to "\r\n"

movb $16, %cl
subb $4, %cl
movw %dx, %ax
shr %cl, %ax
andw $0x000f, %ax
cmpb $10, %al
jl test_word_less
addb $7, %al #prepare for A,B,C...because 17+48=65(A)

addb $48, %al
movb $0xe, %ah
movw $7, %bx
int $0x10
cmpb $0, %cl
jne test_word_loop
movb $13, %al
int $0x10
movb $10, %al
int $0x10

No comments:

Post a Comment