Other Programming Languages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreOther Programming Languages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old May 8th, 2006, 10:41 AM
n000b n000b is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: Melbourne, Australia
Posts: 586 n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 11 h 35 m 44 sec
Reputation Power: 7
Send a message via ICQ to n000b
Assembly: convert hex to decimal

Hi,

Can someone tell me how to convert a 2 digit HEX value to it's decimal equivalent in Assembly please? Or just the theory to do it and I can implement it. It's for the Motorolla 68K processor.

Thanks

Reply With Quote
  #2  
Old May 8th, 2006, 11:53 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 23 m 58 sec
Reputation Power: 999
Theory only, we don't do the work for you

obviously hex has 16 values, 0 - 15, a - f = 10 through 15, i'm sure you konw that much. now, the way it goes to a number is like so

you have your number, lets take 'ab'

a, being the first digit gets multiplied by 16, and b is added on.

There you have your number

You will need your operating system's system call numbers to look at to get input and output. You could instead use the C library on your computer to use functions like printf and scanf (although i'm not sure if your lecturers will allow that)

Good Luck!

Reply With Quote
  #3  
Old May 8th, 2006, 07:07 PM
n000b n000b is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: Melbourne, Australia
Posts: 586 n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 11 h 35 m 44 sec
Reputation Power: 7
Send a message via ICQ to n000b
So it's as simple as multiplying the first by 16 and adding on the second? Thanks mate, that'll help

Reply With Quote
  #4  
Old May 8th, 2006, 07:21 PM
Scorpions4ever's Avatar
Scorpions4ever Scorpions4ever is offline
Banned ;)
Dev Shed God 5th Plane (7000 - 7499 posts)
 
Join Date: Nov 2001
Location: Glendale, Los Angeles County, California, USA
Posts: 7,336 Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level)Scorpions4ever User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 4 Weeks 12 h 46 m 43 sec
Reputation Power: 674
Yep. Theory works like this:
* Consider a number (say 15482) in decimal system
* This is equivalent to (1 * 10000) + (5 * 1000) + (4 * 100) + (8 * 10) + 2
* This is equivalent to (1 * 10^4) + (5 * 10^3) + (4 * 10^2) + (8 * 10^1) + (2 * 10^0)
where ^ is the power-of operator.

* Now consider a number (say 12F3B) in hexadecimal system
* Using similar logic, this is equivalent to (1 * 16^4) + (2 * 16^3) + (F * 16^2) + (3 * 16^1) + (B * 16^0)

Now all you have to do is compute 16^4, 16^3 etc. and also take F=15 and B=11 and there you have it... the answer in decimal

Note that you can use this logic to convert a number from *ANY* base into decimal.
__________________
Up the Irons
What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
"Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
Down with Sharon Osbourne

Puzzle of the Month solved by sizeablegrin, etienne141 and L7Sqr, superior C/C++ programmers of the month

Reply With Quote
  #5  
Old May 8th, 2006, 07:28 PM
n000b n000b is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Location: Melbourne, Australia
Posts: 586 n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level)n000b User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 11 h 35 m 44 sec
Reputation Power: 7
Send a message via ICQ to n000b
Cool, thanks guys

Reply With Quote
  #6  
Old May 8th, 2006, 08:18 PM
Schol-R-LEA's Avatar
Schol-R-LEA Schol-R-LEA is offline
Commie Mutant Traitor
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jun 2004
Location: The People's Republic of Berkeley
Posts: 1,038 Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level)Schol-R-LEA User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 3 Weeks 3 Days 8 h 32 m 33 sec
Reputation Power: 330
I would add that if you needed a more general version of this - one that could handle values that weren't a fixed size - it would probably be easier and more efficient to convert the hex string to a binary integer, and then back to a decimal string, than to write a function specifically for converting hex string to a decimal string - especially since you would need an ASCII to binary integer and binary to ASCII routines anyway, and it's fairly easy to write ones that will handle all bases from 2 to 36.

The general algorithm for converting from binary to a printable ASCII or UNICODE string in a given base is (in Python):

Code:
def int2str(n, base):
	digit = n % base
	
	if base >= 10 and digit >= 10:
		numeral = chr((digit - 10) + ord('A')) 
	
	else:
		numeral = chr(digit + ord('0'))
	
	if base > n:
		return numeral
	else:
		return int2str(n / base, base) + numeral


While this is a recursive algorithm, it is fairly easy to convert it to interation by pushing the resulting digits on the stack and looping, then popping them off when it is done; in assembly language, it amounts to about the same thing either way, really.

The string-to-binary algorithm is more or less the same as the one which LP gave (again, in Python):

Code:
from string import upper

def str2int(s, base):
	accum = 0
	
	# ASCII/UNICODE values of these characters
	zero = ord('0')  
	nine = ord('9')
	alpha = ord('A')
	omega = ord('Z')
	
	for n in range(len(s)):
		numeral = ord(upper(s[-(n+1)]))
		
		if numeral in range(zero, nine):
			accum += (numeral - zero) * (base ** n)
		elif (numeral in range(alpha, omega)) and (base > 10):
			accum += ((numeral - alpha) + 10) * (base ** n)
		else:
			# invalid number
			accum = 0
			break
	return accum


Converting these algorithms into m68K assembly is, of course, left as an excercise.
__________________
Rev First Speaker Schol-R-LEA;2 JAM LCF ELF KoR KCO BiWM TGIF
#define KINSEY (rand() % 7) λ Scheme is the Red Pill
Scheme in ShortUnderstanding the C/C++ Preprocessor
Taming PythonA Highly Opinionated Review of Programming Languages for the Novice, v1.1

FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov

Last edited by Schol-R-LEA : May 8th, 2006 at 08:22 PM.

Reply With Quote
  #7  
Old May 9th, 2006, 01:00 AM
LinuxPenguin's Avatar
LinuxPenguin LinuxPenguin is offline
fork while true;
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: May 2005
Location: England, UK
Posts: 5,535 LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)LinuxPenguin User rank is General (90000 - 100000 Reputation Level)  Folding Points: 11590 Folding Title: Novice Folder
Time spent in forums: 1 Month 3 Weeks 1 Day 19 h 23 m 58 sec
Reputation Power: 999
I'd try Schol-R's method, the code is certainly cleaner, and more flexible too.

Remember that hex is base 16, so to pass that to the function once you've written it

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreOther Programming Languages > Assembly: convert hex to decimal


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway