How do I print an integer that is interpreted as hex?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
stevewoods1986
Member
Member
Posts: 80
Joined: Wed Aug 09, 2017 7:37 am

How do I print an integer that is interpreted as hex?

Post by stevewoods1986 »

Hello.

I want to get a hex value (0x20 for example) and print it as a number (20). However, I'm having trouble.
I know I could just do

Code: Select all

cmp al, 0x20
je twentyprint

twentyprint:
mov ah, 0eh
mov al, 32h
int 10h

mov ah, 0eh
mov al, 30h
int 10h
however, that could use up a lot of space.
I want to print an integer so it shows a number instead of a symbol (like space is 0x20).

What should I do? Get the first nibble and interpret it as 2 and the second nibble as 0?
Knowing how to get a nibble from a register would be good.

Any help would be appreciated.

Thanks
Steve.
User avatar
iansjack
Member
Member
Posts: 4662
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do I print an integer that is interpreted as hex?

Post by iansjack »

Read about the logical "and" and "or" instructions and the shift instructions.

Better yet, get a book on x64 assembler.
User avatar
MichaelFarthing
Member
Member
Posts: 167
Joined: Thu Mar 10, 2016 7:35 am
Location: Lancaster, England, Disunited Kingdom

Re: How do I print an integer that is interpreted as hex?

Post by MichaelFarthing »

How long will everyone be fooled by this troll? Anyone who casually uses a word like nybble can't possibly be innocently making the sort of posts we see.
User avatar
iansjack
Member
Member
Posts: 4662
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do I print an integer that is interpreted as hex?

Post by iansjack »

I'm still prepared to give him the benefit of the doubt. But the OP needs to accept that he is a raw beginner when it comes to assembler, let alone OS programming, rather than of "intermediate" ability. And the best way to remedy that is to do some serious studying rather than clogging up these forums with trivial questions.

More questions at this level and I'd be inclined to believe that he is a troll rather than someone seeking knowledge.
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: How do I print an integer that is interpreted as hex?

Post by BrightLight »

stevewoods1986 wrote:What should I do? Get the first nibble and interpret it as 2 and the second nibble as 0?
Knowing how to get a nibble from a register would be good.
What you want is bit shifting, logical AND and arrays. They are irrelevant to OS development, so should be easy enough for you to figure out on your own.

Think of it this way: if this was in C and you had no itoa() or printf() function, how would you do it? Then after figuring that out, find the assembly instructions that can do that.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: How do I print an integer that is interpreted as hex?

Post by Octacone »

You need two char arrays, one to hold the output and one for the lookup table. Your lookup table needs to contain 16 chars, 0-9 to A-F.
Now what you need to do is: convert every digit to char, put everything inside your output array, print that array.
Take a look at these instructions for how to do it:

Code: Select all

and
shl
shr
Here is an useful clue:
1.ANDing 0xAB by 0x0F will give you B.
2.ANDing 0xAB by 0xF0 will give you A0.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
User avatar
iansjack
Member
Member
Posts: 4662
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do I print an integer that is interpreted as hex?

Post by iansjack »

You really don't need lookup tables.
User avatar
Octacone
Member
Member
Posts: 1138
Joined: Fri Aug 07, 2015 6:13 am

Re: How do I print an integer that is interpreted as hex?

Post by Octacone »

iansjack wrote:You really don't need lookup tables.
True, you could even do it by modular base division and using ('0' + number) for conversion.
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader
stevewoods1986
Member
Member
Posts: 80
Joined: Wed Aug 09, 2017 7:37 am

Re: How do I print an integer that is interpreted as hex?

Post by stevewoods1986 »

Octacone wrote:
iansjack wrote:You really don't need lookup tables.
True, you could even do it by modular base division and using ('0' + number) for conversion.
What is a way of doing it? To be quite honest, I'm not the most experienced with instructions like AND and OR.
User avatar
obiwac
Member
Member
Posts: 149
Joined: Fri Jan 27, 2017 12:15 pm
Libera.chat IRC: obiwac
Location: Belgium

Re: How do I print an integer that is interpreted as hex?

Post by obiwac »

I'm not the most experienced with instructions like AND and OR.
Ok hes a troll.
User avatar
iansjack
Member
Member
Posts: 4662
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do I print an integer that is interpreted as hex?

Post by iansjack »

stevewoods1986 wrote:To be quite honest, I'm not the most experienced with instructions like AND and OR.
Then, for goodness sake, do us all a favour. Go and learn a little about computer, programming, data structures, algorithms, etc., rather than wasting our time.
User avatar
Geri
Member
Member
Posts: 442
Joined: Sun Jul 14, 2013 6:01 pm

Re: How do I print an integer that is interpreted as hex?

Post by Geri »

Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html
stevewoods1986
Member
Member
Posts: 80
Joined: Wed Aug 09, 2017 7:37 am

Re: How do I print an integer that is interpreted as hex?

Post by stevewoods1986 »

iansjack wrote:
stevewoods1986 wrote:To be quite honest, I'm not the most experienced with instructions like AND and OR.
Then, for goodness sake, do us all a favour. Go and learn a little about computer, programming, data structures, algorithms, etc., rather than wasting our time.
I say I'm not the most experienced. I am not the expert on it. I understand about bitwise logic, OK? I might know more if I could print an integer.
Geri wrote:https://www.youtube.com/watch?v=jIo-Ea6GO64
I don't need this (BLEEP), ok? Understand? I'm already (BLEEP) (BLEEP)...ed off by everyone. Why do I have to be suggested things? I'm not wasting your time. Don't give me animated witch videos that looks like something from Pokemon. I actually saw a Pokemon advert while writing this :)

I can't believe you would link me to such (BLEEP). What do you think that video was going to do? Was it going to change anything or was it going to make this thread infected?

It's not my fault why most of you cause problems. Everyone here is a know-it-all. Ever head of Newton's Law?.

Sorry, about my swearing even if I bleeped it.

I want an answer, not complaining because you don't know the answer. If you don't know the answer, don't post.
I don't want trouble. I want an answer.

Why does every single forum thread get infected by people who complain.
Last edited by stevewoods1986 on Thu Aug 17, 2017 1:01 pm, edited 1 time in total.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: How do I print an integer that is interpreted as hex?

Post by neon »

Hello,

You asked What is a way of doing it? after having already been given two different ways of doing it. No follow up questions from those responses. No attempt to figure out the algorithms they gave you. It is as if you completely ignored them thinking those responses were irrelevant.

You said you don't want suggestions. In the previous thread you said you don't want code or sample code. So: what do you want? Pseudo code? Links? A walkthrough tutorial? What can we do to provide you with what you want since apparently the two replies that provided correct solutions was not satisfactory?
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
stevewoods1986
Member
Member
Posts: 80
Joined: Wed Aug 09, 2017 7:37 am

Re: How do I print an integer that is interpreted as hex?

Post by stevewoods1986 »

neon wrote:Hello,

You asked What is a way of doing it? after having already been given two different ways of doing it. No follow up questions from those responses. No attempt to figure out the algorithms they gave you. It is as if you completely ignored them thinking those responses were irrelevant.

You said you don't want suggestions. In the previous thread you said you don't want code or sample code. So: what do you want? Pseudo code? Links? A walkthrough tutorial? What can we do to provide you with what you want since apparently the two replies that provided correct solutions was not satisfactory?
I don't want a puzzle. Fine, I'll figure it out.
Locked