Example for many applications we want to convert the

This preview shows page 4 - 6 out of 22 pages.

Example: For many applications, we want to convert the ASCII code to its simple BCD equivalent. This can be done by simply replacing the bits in the upper nibble (a nibble = 4 bits) of the byte by four zeros. The number obtained is called unpacked BCD nurnbcr. The upper nibble of these is zero. So the upper nibble can be used to store another unpacked BCD number. The byte thus obtained is called packed BCD number. The algorithm to convert two ASCII codes to packed BCD can be stated as: Convert first ASCII number to unpacked BCD. Convert the second ASCII number to unpacked BCD number Move first BCD nibble to upper nibble position in byte. Pack two BCD nibbles in one byte The assembly language program for the above can he written in the following manner. ; ABSTRACT ; Program produces a packed BCD byte from 2 ASCII- ; encoded digits. The number is 59. ; The first ASCII digit (5) is loaded in BL. ; The second ASCII digit (9) is loaded in AL. ; The result (packed BCD) is left in AL ; REGISTERS ; Uses CS, AL, BL, CL ;PORTS ; None used CODE SEGMENT ASSUME CS:CODE START: MOV BL, '5' ; Load first ASCII digit into BL MOV AL, '9 ; Load second ASCII digit into AL AND BL, OFh ; Mask upper 4 bits (nibble) of first ; digit AND AL, OFh ; Mask upper 4 bits of second digit MOV CL, 04h ; Load CL for 4 rotares required
Image of page 4

Subscribe to view the full document.

ROI- BI.. C 1. ; Rotate BL 4 bit positions C)R tZ I.. RL. ; Combine nihhlcs, result in AL contains 59 : as packed BCD CODE ENDS END START You would find in the aho\.c csamplc. that we are using ROL and OR instructions. 8086 docs not ha\v any instruction to swap two nibbles in a byte, it can however exchange two hytcs or words using XCHG instruction. Out of the two rotate instructions, ROL ancl RCYL. we ha\x chosen ROL, for the following rcason. ROL rotates Icft the byte Icft by one or more positions, bringing the MSB into LSB i position and also mo\.ing it into thc carry bit. RCL on thc other hand, moves thc MSB into the carry l1;1g and brings the original carry flag inln the LSB position. Lvhich is not whirl we want. By using ROL four times we can mo\:c thc upper nibblc into thc Iowcr nil>hlc position, and the lower nithle into the upper one. b Lct us now look at irn csiini~lc using RCL instruction. This will makc the differcncc hct\vccn the instrurtion~ clcirr. The folio\\-ing program adds a hytc numhcr from one mcmory location to a byte I'roni thc ncst memory location. puts the sum in the third mcmory location. and ~ i v c the %talc of the carry flag in ~ h c least significant bit of the fourth mcmory location. The upper 7 141s of the memory location where the carry is storcd arc n~;r\L;ccl. :ABSTRACT : -This program adds 2 8-hit words in the memory locations : called SUM1 and SL'M9,. The rcsult is storcd in : thc memory location cirllcd RESULT. If thcrc : wa\ 3 carry from the addition then it will he : storcd from the addition it will be stored as :oOOO 0001 in thc location CARRY ) ; ALCiORITHM: gct NUMl add NUM2 put sum into memory at SUM , position carry in LSB of byte r mask off upper seven bits , store the result in the carry location.
Image of page 5
Image of page 6
You've reached the end of this preview.
  • Spring '10
  • Ramon
  • Assembly Language, X86, Binary numeral system, ........., Binary-coded decimal, ax

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern