hw5sol

# hw5sol - M7 X<(A BC(D – EF Q2 CMP X,Y computes Y – X...

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

C-355-701 Solutions to HW # 5 Q1. Problem 10.6 The memory map is as follows: M1 A M2 B M3 C M4 D M5 E M6 F M7 X = (A+BC)/(D-EF) M8 temp (extra location to store intermediate result) 3- address code: MUL M7,M2,M3 X<-BC ADD M7,M7,M1 X <- A+BC MUL M8,M5,M6 temp <- EF SUB M8, M4,M8 temp <- D – EF DIV M7,M7,M8 X <- (A+BC)/(D-EF) 2-address code: MOV M7,M5 X <- E MUL M7,M6 X <- EF MOV M8,M4 temp <-D SUB M8,M7 temp <- D-EF MOV M7,M2 X <- B MUL M7,M3 X <- BC ADD M7,M1 X <- A+BC DIV M7,M8 X <- (A+BC)/(D-EF) 1-address code: LOAD M5 AC <- E MUL M6 AC <- EF STORE M7 X <- EF LOAD M4 AC <- D SUB M7 AC <- D – EF STORE M7 X <- D – EF LOAD M2 AC <- B MUL M3 AC <- BC ADD M1 AC <- A+BC DIV M7 AC <- (A+BC)/(D-EF) STORE M7 X <- (A+BC)/(D-EF)

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

View Full Document
0 – address code: Instruction Stack contents from top PUSH M2 B PUSH M3 C , B MUL BC PUSH M1 A , BC ADD A+BC PUSH M4 D , A +BC PUSH M5 E , A + BC PUSH M6 F,E,D, A +BC MUL EF , D ,A +BC SUB D – EF, A +BC DIV (A+BC)/(D-EF) POP
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: M7 X <- (A+BC)/(D – EF) Q2. CMP X,Y computes Y – X and sets the flags depending on the result. Y = 37h = 00110111 X = 49h = 01001001 Perform subtraction by 2’s complement addition 00110111 + 10110111 11101110 Remember that carry is meaningful only in unsigned arithmetic. In unsigned subtraction, absence of carry indicates borrow and therefore CF=1. Overflow and sign are meaningful only in signed arithmetic. There is no overflow , so OF=0 Result is negative so SF=1 Result is not zero, so ZF=0 (meaningful both in unsigned and signed) Q3. For this question, Parity Flag PF is also needed. Since there are 6 ones in the result PF =1 (even parity) Branch Taken/Not Taken Reason JA NT C=1 JAE NT C=1 JB T C=1 JBE T C=1 JE NT Z=0 JG NT S=1, O=0 JGE NT S=1,O=0 JL T S=1,O=0 JLE T S=1,O=0 JNE T Z=0 JNO T O=0 JNS NT S=1 JNP NT P=1 JO NT O=0 JP T P=1 JS T S=1...
View Full Document

{[ snackBarMessage ]}

### Page1 / 3

hw5sol - M7 X<(A BC(D – EF Q2 CMP X,Y computes Y – X...

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

View Full Document
Ask a homework question - tutors are online