;;;;;;;;;;;;;;;;;;;;;;;;; Fill in the blanks with the ;;;;;;;;;;;;;;;;;;;;;;;;; values of the registers. mov cx, 2 mov dx, 32 mov ah, 2 ; AH AL (hex) mov al, "9" ; 02 39 inc al ; 02 3A idiv dx ; _ _ _ _ shl ax, cx ; _ _ _ _ inc ax ; _ _ _ _ ;;;;;;;;;;;;;;;;;;;;; ; BH BL (hex) mov bh, "6" mov bl, 2 ; _ _ _ _ add bl, bh ; _ _ _ _ shl bx ; _ _ _ _ mov P, ax mov Q, bx ; MEMORY at 0400h ; "__ __ __ __" .DATA .ORG 0400h P DW "Ne" Q DW "eD"
if (P > Q) {S= P} else {S= Q}; // This could have been written as "S= P>Q ? P : Q;
if (U>V && U>W) // then { P= U; Q= V; } else { P= V; Q= U; }Optimize your code to reduce the number of instructions as much as possible.
//////// Compute 8! = 8*7*6*5*483*2*1 int fac=1; int num=8; do { fac= fac * num num= num - 1 } while (num>0); // //This might also have been written as: // for ( ; fac *= num--; num>0 )Now complete the following assembler code, to do the same thing.
.DATA NUM DW 8 FAC DW mov ax, NUM ; Starting number mov dx, 1
(b.) Explain what would happen if the starting value
for "NUM" was changed from seven to seventeen (17),
and how you would change this code to fix the problem.
; Save and restore the registers mov Asave, ax ; Store AX in memory mov ah, bh ; Move BH to AX mov al, bl ; Move BL to AX mov Bsave, ax ; Save contents of BX call UnsafeSub ; Call the procedure mov ax, Bsave ; Fetch saved value of BX mov bx, ax mov ax, Asave ; Restore AX
(b.) Simplify the code further, using more-appropriate instructions.