CS301 – Fall 2003

Prof. Hartman

Homework #3

Due Monday, October 6th by 4:45 pm

  1. Write an assembly language program to implement the following C++ code. Do not just duplicate the output – make your code function the same way.


int a, i, z;

cout << "Enter z (z>0): ";

cin >> z;

for (i=0; i<=z; i++)


     a = i % 2;

     if (a == 0)

     cout << i << endl;



You may use the I/O routines from Carter’s book. Refer to the handout about using NASM with Windows and Visual C++ for links to the I/O files if you don’t have them. Hand in your program listing and a sample run showing z=10. Explain in English what the program does. For full credit you must turn in a well-commented listing including your name and the problem number.


  1. For each of the following instructions, indicate the result. Assume BYTE1 is a memory location containing 5Fh:






mov cx,25h

; cx  = 0000h

cx  =


mov cl,0

; cx  = 0ffffh

cx  =


mov dh,[BYTE1]

; dx  = 0beefh

dx  =


xchg ah,al

; ax  = 1234h

ax  =


xor eax,eax

; eax = 12345678h

eax =


inc dl

; dx  = 0ffffh

dx  =


inc dx

; dx  = 0ffffh

dx  =


  1. In what significant way do the following instructions differ in execution?

                mov eax, 1234ABCDh
                mov [eax], 1234ABCDh