CS 2011, C Term 2002: Lab 3

                                                                           Name: ______________

                                                                            Section:_______________

Objective

The goal of this lab is give you some practice with using indirect addressing to read through a list of numbers. You've already done this in machine code, now you get to do it using the assembly language!  One major difference - you will not be initializing DS, CS, or IP.  If you have your hw2 code available you should be able to just look up some of the instructions. 
  1. Enter your program. Use the following code as a skeleton. The comments indicate what each missing instruction needs to do:
    	TITLE	Program counts the negative numbers stored in an "array"
    	.model	small		;start all programs you will write 
    	.stack	100h		;for CS2011 with these directives
    
    	.data			;the program's variables go here
    ourdat 	dw		400, 16, -25, -49, -160, 18
    datlen = ($ - ourdat)/2		    ; datlen = length of the data
    
    	.code			    ;the code starts here
    	.startup		    ;TASM directive that sets up stack
    				    ;segment and data segment
    	
    	mov	bx, offset ourdat   ;initialize bx to point to our data
    
    	;now write the code for the following instructions (down until the nop)
    
    				   ;store the data length in CX
    
        				   ;move the word pointed to by BX 
    				   ;   to AX
    
    				   ;add 2 to BX
    
    				   ;subtract 1 from CX
label1:  				;move (copy) the word pointed to by BX to DX

					;compare AX to DX

     					;if AX <= DX then jump forward to the  
					;  instruction at label2

					;move DX to AX

label2:	  				;add 2 to BX

					;subtract 1 from CX

					;compare CX to 0

     					;if CX > 0 then jump back to the
					;  instruction at label1

label3:	nop				;return to DOS - the .exit takes care 
					;of that!
	.exit				;a TASM directive that returns 
					;control to the calling program.
					;Meant to be used in conjunction
					;with .startup
	end				;end of source code
  1. Using the instructions found at:

    http://www.cs.wpi.edu/~jburge/courses/c02/cs2011/tasm_instructions.html
     

    assemble and link your program.  You may want to save a copy to  a floppy disk to reference it later.

  2.  Once you have successfully built the program, bring up the turbo debugger.  Then,

    You will need to turn in this handout at the end of your lab session to receive credit for the lab.