CS301 – Fall 2002

Prof. Hartman

Homework #3

Due Friday, September 27th by 5:00 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:

 

Instruction

Before

After

a)

mov cx,25h

; cx  = 0000h

cx  =

b)

mov cl,0

; cx  = 0ffffh

cx  =

c)

mov dh,[BYTE1]

; dx  = 0beefh

dx  =

d)

xchg ah,al

; ax  = 1234h

ax  =

e)

xor eax,eax

; eax = 12345678h

eax =

f)

inc dl

; dx  = 0ffffh

dx  =

g)

inc dx

; dx  = 0ffffh

dx  =

 

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

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

    b) What kind of addressing is involved in the second instruction?