CSCI 110, Spring 2011
Home | | Course Schedule | | Assignments | | Lecture NotesHomework 8 solution
Problem 1.IN AX COPY M1, AX SUB AX, M1 CMP AX, M1 JB LAB1 OUT AX JMP LAB2 LAB1 COPY AX, M1 DIV AX, M1 OUT AX LAB2 END
a) What is the output of the above program if the input is 4?
b) What is the output of the above program if the input is 0?
c) Briefly describe how the program works.
Problem 2.
Write an assembly language program that reads two integers and prints their sum.
IN AX COPY X, AX IN AX ADD AX, X OUT AX END
Problem 3.
P88 Instructions to enter 2 numbers and print out the larger of the two:
There are many possible solutions. Here is one:
IN AX {Enter 1st number} COPY X, AX {Copy 1st number into X} IN AX {Enter 2nd number} COPY Y, AX {Copy 2nd number into Y (optional)} CMP AX, X {if AX < X set CF = B, else CF = NB} JNB PRINT {if AX >= X print it out} COPY AX, X {copy 1st number back into AX, since it's biggest} PRINT OUT AX {Print out number that's in accumulator} END
Alternative solution:
IN AX {Enter 1st number} COPY X, AX {Copy 1st number into X} IN AX {Enter 2nd number} COPY Y, AX {Copy 2nd number into Y (optional)} CMP AX, X {if AX < X set CF = B, else CF = NB} JB LABEL1 {if AX < X jump to LABEL1} OUT AX {if AX >= X print it out} JMP LABEL2 {Jump to the end} LABEL1 COPY AX, X {Copy from X to the accumulator} OUT AX LABEL2 END