Assignment Document

Arithmetic and Logic Instructions And Programs

Pages:

Preview:


  • "ORG ; THREEArithmeticand LogicInstructionsAnd Programs OBJECTIVESthis chapter enables the student to:• Demonstrate how 8-bit and 16-bit unsignednumbers are added in the x86.• Convert data to any of the forms:– ASCII,packed BCD,unpacked BCD.• Explain..

Preview Container:


  • "ORG ; THREEArithmeticand LogicInstructionsAnd Programs OBJECTIVESthis chapter enables the student to:• Demonstrate how 8-bit and 16-bit unsignednumbers are added in the x86.• Convert data to any of the forms:– ASCII,packed BCD,unpacked BCD.• Explain the effect of unsigned arithmeticinstructions on the flags.• Code the following Assembly language unsignedarithmetic instructions:– Addition instructions: ADD and ADC.– Subtraction instructions SUB and SBB.– Multiplication and division instructions MUL and DIV. OBJECTIVES(cont)this chapter enables the student to:• Code BCD arithmetic instructions:– DAA and DAS.• Code the Assembly language logic instructions:– AND, OR, and XOR.– Logical shift instructions SHR and SHL.– The compare instruction CMP.• Code bitwise rotation instructions– ROR, ROL, RCR, and RCL.• Demonstrate an ability to use all of the aboveinstructions in Assembly language programs.• Perform bitwise manipulation using the C language. 3.0: UNSIGNED ADDITION AND SUBTRACTION • Unsigned numbers are defined as data in which allthe bits are used to represent data.– Applies to the ADD and SUB instructions.– No bits are set aside for the positive or negative sign. • Between 00 and FFH (0 to 255 decimal) for 8-bit data.• Between 0000 and FFFFH (0 to 65535 decimal) for 16-bit data. 3.1: UNSIGNED ADDITION AND SUBTRACTIONaddition of unsigned numbers• The form of the ADD instruction is:• ADD and ADC are used to add two operands. – The destination operand can be a register or in memory. – The source operand can be a register, in memory, orimmediate. • Memory-to-memory operations are never allowedin x86 Assembly language. – The instruction could change ZF, SF, AF, CF, or PF bits ofthe flag register.3.1: UNSIGNED ADDITION AND SUBTRACTIONaddition of unsigned numbers 3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE1 addition of individual byte/word data• Program 3-1a uses AH to accumulate carries as theoperands are added to AL. See the entire program listing on page 93 of your textbook. 3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE1 addition of individual byte/word data• Numbers are converted to hex by the assembler:– 125=7DH 235=0EBH 197=0C5H 91=5BH 48=30H • Three iterations of the loop are shown below. – In the first, 7DH is added to AL.• CF = 0 and AH = 00. • CX = 04 and ZF = 0.– Second, EBH is added to AL & since a carry occurred, AH is incremented• AL = 68H and CF = 1. • CX = 03 and ZF = 0.– Third, C5H is added to AL, again a carry increments AH.• AL = 2DH, CX = 02 and ZF = 0. 3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE1 addition of individual byte/word data• This process continues until CX = 00 and the zeroflag becomes 1, causing JNZ to fall through. – The result will be saved in the word-sized memory setaside in the data segment.3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE1 addition of individual byte/word data• Due to pipelining it is strongly recommended thatthe following lines of the program be replaced:– The "ADC AH,00" instruction in reality means add00+AH+CF and place the result in AH. • More efficient since the instruction "JNC OVER" has to emptythe queue of pipelined instructions and fetch the instructionsfrom the OVER target every time the carry is zero (CF = 0).• Program 3-1b is the same as 3-1a, rewritten for word addition.(See the program listing on page 94 of your textbook.) 3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE2 addition of multiword numbers• Assume a program to total U.S. budget for the last100 years or mass of planets in the solar system. – Numbers being added could be 8 bytes wide or more. • The programmer must write the code to break thelarge numbers into smaller chunks to be processed. – A 16-bit register & an 8 byte operand is wide wouldtake a total of four iterations. – An 8-bit register with the same operands would requireeight iterations.3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE2 addition of multiword numbers• In writing program 3-2, the first decision was thedirective for coding the data in the data segment. DQ was chosen since it canrepresent data as large as8 bytes wide. See the entire program listing on page 95 of your textbook. 3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE2 addition of multiword numbers• In addition of multibyte (or multiword) numbers, theADC instruction is always used, as the carry mustbe added to the next-higher byte (or word) in thenext iteration. – Before executing ADC, the carry flag is cleared(CF = 0) using the CLC (clear carry) instruction. • Three pointers have been used: – SI for DATA1; DI for DATA2.– BX for DATA3. (where the result is saved) 3.1: UNSIGNED ADDITION AND SUBTRACTIONCASE2 addition of multiword numbers• A new instruction, "LOOP XXXX", replaces the oftenused "DEC CX" and "JNZ XXXX". – When "LOOP xxxx" is executed, CX decrementsautomatically, and if CX is not 0, the processor willjump to target address xxxx. • If CX is 0, the next instruction (below "LOOP xxxx") isexecuted. 3.1: UNSIGNED ADDITION AND SUBTRACTIONsubtraction of unsigned numbers• In subtraction, x86 processors use 2's complement. – Internal adder circuitry performs the subtraction command. • x86 steps in executing the SUB instruction:– 1. Take the 2's complement of the subtrahend.(source operand)– 2. Add it to the minuend. (destination operand)– 3. Invert the carry.• The steps are performed for every SUB instructionregardless of source & destination of the operands."

Related Documents

Start searching more documents, lectures and notes - A complete study guide!
More than 25,19,89,788+ documents are uploaded!

Why US?

Because we aim to spread high-quality education or digital products, thus our services are used worldwide.
Few Reasons to Build Trust with Students.

128+

Countries

24x7

Hours of Working

89.2 %

Customer Retention

9521+

Experts Team

7+

Years of Business

9,67,789 +

Solved Problems

Search Solved Classroom Assignments & Textbook Solutions

A huge collection of quality study resources. More than 18,98,789 solved problems, classroom assignments, textbooks solutions.

Scroll to Top