Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
All I am trying to do is print the hexadecimal value of a number in bootloader.

Architecture:

Intel x86
Mode: real
Assembler: GNU AS
Syntax: AT&T

But I dont know...something seems to be wrong. I am using a simple logic to achieve the same. I know that word can store a maximum of 65535 but I am not able to print all numbers properly.

movw $16, %ax
call .printhexa

.printhexa:
   cmpw $16, %ax
   jl   .printhexa2
   
   movw $16, %bx
   divw %bx

   #####
   use %dx to 
   print the respective hexadecimal digit
   #####
   
   jmp .printhexa

.printhexa2:
   #####
   use %ax to
   print the respective hexadecimal digit
   #####
   
ret



can you please help. Is there any limitation to print the hexadecimals in real mode ???
Posted
Updated 21-Aug-13 7:03am
v2
Comments
pasztorpisti 21-Aug-13 13:08pm    
This simple task has nothing to do with real mode.

1 solution

If you store a number in registers then of course you can store only 16 bit numbers in 16 bit registers. But if you store a number in memory then it can be as long as you want. If it is 64 bits (8 bytes) you can still print it as hex, you could do the same with 128 bit (16 byte numbers) or with 100 byte long integers... You pick up the most significant byte and you convert it into two hex digits, then in a loop you pick up the next most significant byte and then print it as 2 hex digits. You simply can't store everything in registers, the number of registers and the size of these registers is limited.
 
Share this answer
 
Comments
AshakiranBhatter 21-Aug-13 14:05pm    
I know its not about real mode but the problem seems to be stranger to me.

I tried the following code and it even gives the wrong result.

movw $0xffff, %ax
.begin:
cmpw $16, %ax
jl .endnow
movb $'n', %al
movb $0x0e, %ah
int $0x10
jmp .begin

.endnow:
movb $'y', %al
movb $0x0e, %ah
int $0x10


result: y

the result should be infinite loop of n's
pasztorpisti 21-Aug-13 14:19pm    
Why on earth do you use this disgusting GNU as? If your OS is windows then use the good old tasm instead: link.

I've never used gas and I simply can't decide what is the order of cmp operands. BTW do you know that there are signed and unsigned conditional jump instructions??? jl is signed (Jump if Less) while its unsigned pair is jb (Jump if Below). If you have no clue about this then read the following: link. 0xffff can be treated as 65535 as unsigned but if you treat it as signed then it translates to -1. The jl instructions is signed so it treats 0xffff as -1.

BTW: before jumping back to .begin you are calling a bios video interrupt. What guarantees that it doesn't change the value of ax? I haven't read the documentation of the 0x0e function (although I've used it a lot long ago) but I never assumed anything about the value of ax after calling that bios function.
AshakiranBhatter 21-Aug-13 14:28pm    
I just started liking AT&T syntax of GNU Assembler. Thats why I am giving it a try. JB sure does work and thank you for your help clearing my doubts. :)
pasztorpisti 21-Aug-13 15:06pm    
You are welcome! GNU as syntax sucks! GNU assembly is probably used only by programs that output this ugly assembly code... maybe not... Learn the 2's complement if you haven't yet done that because its a very basic and important thing!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900