Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
 Home Forums HCL Reviews Tutorials Articles Register Search Today's Posts Mark Forums Read
 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

 04-10-2011, 10:47 AM #1 topheraholic Member   Registered: Aug 2008 Location: shanghai Distribution: ubuntu Posts: 128 Rep: 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??```
 04-10-2011, 01:46 PM #2 paulsm4 LQ Guru   Registered: Mar 2004 Distribution: SusE 8.2 Posts: 5,863 Blog Entries: 1 Rep: 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.
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,070

Rep:
Quote:
 Originally Posted by topheraholic 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.

04-11-2011, 09:01 AM   #4
topheraholic
Member

Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep:
Quote:
 Originally Posted by paulsm4 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!

04-11-2011, 09:03 AM   #5
topheraholic
Member

Registered: Aug 2008
Location: shanghai
Distribution: ubuntu
Posts: 128

Original Poster
Rep:
Quote:
 Originally Posted by salasi 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?

 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 Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post topheraholic Programming 6 03-21-2011 03:35 PM topheraholic Programming 6 03-19-2011 09:15 PM theKbStockpiler Programming 4 01-30-2011 10:09 AM ashlesha Programming 2 09-13-2006 05:11 AM jclark00001 Programming 3 02-26-2003 09:52 PM

LinuxQuestions.org

All times are GMT -5. The time now is 05:54 PM.

 Contact Us - Advertising Info - Rules - LQ Merchandise - Donations - Contributing Member - LQ Sitemap -