OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 6:14 am

All times are UTC - 6 hours




Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 37 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 5:36 am 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
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:
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.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 6:05 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
Read about the logical "and" and "or" instructions and the shift instructions.

Better yet, get a book on x64 assembler.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 6:15 am 
Offline
Member
Member
User avatar

Joined: Thu Mar 10, 2016 7:35 am
Posts: 167
Location: Lancaster, England, Disunited Kingdom
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.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 6:26 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 6:44 am 
Offline
Member
Member
User avatar

Joined: Sat Dec 27, 2014 9:11 am
Posts: 901
Location: Maadi, Cairo, Egypt
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.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 7:21 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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:
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


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 8:35 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
You really don't need lookup tables.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 9:05 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 10:19 am 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
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.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 10:58 am 
Offline
Member
Member
User avatar

Joined: Fri Jan 27, 2017 12:15 pm
Posts: 149
Location: Belgium
Quote:
I'm not the most experienced with instructions like AND and OR.


Ok hes a troll.

_________________
AQUA OS: https://obiwac.wordpress.com/aqua-os/


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 11:16 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4591
Location: Chichester, UK
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.


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 11:40 am 
Offline
Member
Member
User avatar

Joined: Sun Jul 14, 2013 6:01 pm
Posts: 442
https://www.youtube.com/watch?v=jIo-Ea6GO64

_________________
Operating system for SUBLEQ cpu architecture:
http://users.atw.hu/gerigeri/DawnOS/download.html


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 12:38 pm 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
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.

Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 1:00 pm 
Offline
Member
Member
User avatar

Joined: Sun Feb 18, 2007 7:28 pm
Posts: 1564
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();}


Top
 Profile  
 
 Post subject: Re: How do I print an integer that is interpreted as hex?
PostPosted: Thu Aug 17, 2017 1:03 pm 
Offline
Member
Member

Joined: Wed Aug 09, 2017 7:37 am
Posts: 80
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic This topic is locked, you cannot edit posts or make further replies.  [ 37 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], SemrushBot [Bot] and 51 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group