eee410_lecture9 - EEE 410 – Microprocessors I Spring...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EEE 410 – Microprocessors I Spring 04/05 – Lecture Notes # 9 Outline of the Lecture • Unsigned Subtraction • Unsigned Multiplication and Division • Arithmetic and Logic Instructions and Programs S UBTRACTION OF UNSIGNED NUMBERS SUB dest,source ; dest = dest - source ¾ In subtraction 2’s complement method is used. ¾ Execution of 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 Ex: MOV AL,3FH ; load AL=3FH MOV BH,23H ; load BH=23H SUB AL,BH ; subtract BH from AL. Place result in AL Execution steps: AL 3F 0011 1111 0011 1111 – BH – 23 – 0010 0011 + 1100 0001 (2’s complement) 1C 0001 1100 1 0001 1100 (CF=0) Step 3 CF=0, ZF=0, PF=0, SF=0. • If the CF=0, the result is positive and the destination has the result. • If the CF=1, the result is negative and the destination has the 2’s complement of the result. NOT and INC increment instructions can be used to change it. Ex: ;from the data segment: DATA1 DB 4CH DATA2 DB 6EH RESULT DB ? ;from the code segment: MOV DH,DATA1 ;load DH with DATA1 value (4CH) SUB DH,DATA2 ;subtract DATA2 (6E) from DH (4C) JNC NEXT ;if CF=0 jump to NEXT target NOT DH ;if CF=1 take the 1’s complement INC DH ;and increment to get 2’s complement NEXT : MOV RESULT,DH ;save DH in RESULT Analysis: Following the 3 steps for “SUB DH,DATA2” 4C 0100 1100 0100 1100 – 6E 0110 1110 2’s comp + 1001 0010 – 22 0 1101 1110 CF=1(Step 3) the result is negative • SBB (subtract with borrow) SBB dest,source ; dest = dest - source - CF ¾ Used in multibyte (multiword) numbers....
View Full Document

This note was uploaded on 05/26/2011 for the course EEE 410 taught by Professor Hasandemirel during the Spring '10 term at Eastern Mediterranean University.

Page1 / 5

eee410_lecture9 - EEE 410 – Microprocessors I Spring...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online