LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2011, 10:47 AM   #1
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Rep: Reputation: 15
Question assembly language! please help me! thanks in advance!


how does AAA(ASCII adjust after addition) really works?
how does Binary-Coded Decimal addition really works?

how to change 006Ah to 0100h after use aaa?

Code:
mov ah, 0  
mov al,'8'    /* AX = 0038h(0011 1000)
add al,'2'    /* AX = 0038h + 0032h = 006Ah,right?
aaa           /* AX = 0100h, so why??
 
Old 04-10-2011, 01:46 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
The key thing about "Binary Coded Decimal" (BCD) is that each byte only holds decimal digits (values between 0..9). It's often used in controller applications (e.g. a clock or timer that needs to display decimal values).

So the number "123" (decimal "one hundred twenty three") is represented like this:

Code:
Binary  BCD
------  ---
0x007b  0x0123
The example above used "packed BCD" - two digits per byte. As you can see, its less efficient than binary.

"Unpacked BCD" is even LESS efficient: you only store ONE decimal digit per byte.

Here are two good links:
http://en.wikipedia.org/wiki/Intel_BCD_opcode
http://www.arl.wustl.edu/~lockwood/c..._6/CH06-2.html
<= Search for "aaa and daa instructions"

PS:
As you're probably aware, the general BCD instructions (the kind you're using above) only support signed arithmetic.

PPS:
A good book (if I haven't already recommended it to you), is:
"Professional Assembly Language", Richard Blum

Last edited by paulsm4; 04-10-2011 at 02:35 PM.
 
Old 04-10-2011, 03:39 PM   #3
salasi
Senior Member
 
Registered: Jul 2007
Location: Directly above centre of the earth, UK
Distribution: SuSE, plus some hopping
Posts: 4,064

Rep: Reputation: 894Reputation: 894Reputation: 894Reputation: 894Reputation: 894Reputation: 894Reputation: 894
Quote:
Originally Posted by topheraholic View Post
how does Binary-Coded Decimal addition really works?
Oh, stuff, I don't think that you really mean you want to know how BCD arith really works, but, just in case I'm wrong. If you go to http://www.educypedia.be/electronics...arithmetic.htm and download the datasheet on, eg, the 74F283, you'll see that on page 3 there is a logic diagram for a binary half adder. This is how a normal half-adder works.

Now further down that page, if you look at http://mayaweb.upr.clu.edu/~borges/Chp5.pdf, you'll see an excellent tutorial on how the more complex circuits, including BCD are constructed. And now you know that, you should be able to work out why the original Z80 has a four bit alu, why it didn't look like that to a programmer (ie, took two passes through the 4 bit alu to do eight bith math) and why it was a bad idea.
 
Old 04-11-2011, 09:01 AM   #4
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by paulsm4 View Post
The key thing about "Binary Coded Decimal" (BCD) is that each byte only holds decimal digits (values between 0..9). It's often used in controller applications (e.g. a clock or timer that needs to display decimal values).

So the number "123" (decimal "one hundred twenty three") is represented like this:

Code:
Binary  BCD
------  ---
0x007b  0x0123
The example above used "packed BCD" - two digits per byte. As you can see, its less efficient than binary.

"Unpacked BCD" is even LESS efficient: you only store ONE decimal digit per byte.

Here are two good links:
http://en.wikipedia.org/wiki/Intel_BCD_opcode
http://www.arl.wustl.edu/~lockwood/c..._6/CH06-2.html
<= Search for "aaa and daa instructions"

PS:
As you're probably aware, the general BCD instructions (the kind you're using above) only support signed arithmetic.

PPS:
A good book (if I haven't already recommended it to you), is:
"Professional Assembly Language", Richard Blum
thanks! but i donot understand this!! sorry!
 
Old 04-11-2011, 09:03 AM   #5
topheraholic
Member
 
Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by salasi View Post
Oh, stuff, I don't think that you really mean you want to know how BCD arith really works, but, just in case I'm wrong. If you go to http://www.educypedia.be/electronics...arithmetic.htm and download the datasheet on, eg, the 74F283, you'll see that on page 3 there is a logic diagram for a binary half adder. This is how a normal half-adder works.

Now further down that page, if you look at http://mayaweb.upr.clu.edu/~borges/Chp5.pdf, you'll see an excellent tutorial on how the more complex circuits, including BCD are constructed. And now you know that, you should be able to work out why the original Z80 has a four bit alu, why it didn't look like that to a programmer (ie, took two passes through the 4 bit alu to do eight bith math) and why it was a bad idea.
i just wanna know how this works?do you know?thanks!
Code:
mov ah, 0  
mov al,'8'    /* AX = 0038h(0011 1000)
add al,'2'    /* AX = 0038h + 0032h = 006Ah,right?
aaa           /* AX = 0100h, so why??
why AX is 0100h?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
assembly language! please help me! thanks in advance! topheraholic Programming 6 03-21-2011 03:35 PM
assembly language! please help me! thanks in advance! topheraholic Programming 6 03-19-2011 09:15 PM
Is Assembly Language considered a Structured Language? theKbStockpiler Programming 4 01-30-2011 10:09 AM
assembly language: ret>>=10 ashlesha Programming 2 09-13-2006 05:11 AM
SPARC assembly language jclark00001 Programming 3 02-26-2003 09:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration