Department of Electrical and Computer Engineering The University of Texas at Austin EE 306 Fall, 2002 Supplemental Note October 23, 2002 A cleaner copy of the program we developed in class today. Note the use of ; in the first column as a way to separate the code into modules. Since the ; starts the line, and since everything after the ; is discarded, as far as the Assembler is concerned, this is simply a blank line. Note we broke the code into pieces, corresponding to the pieces on the expanded flow chart. MOST IMPORTANTLY: Note that the .END comes at the END of the assembly language program. In my hurriedness in class today, I forgot that everything we were writing on the board at the moment was to fit just in front of the FILEADDR location. Thus, the .END should not have come after the TRAP x25, but rather after the ASCII location as shown below. .ORIG x3000 TRAP x23 ; R0 CONTAINS INPUT CHAR AND R1,R1,#0 ; R1 CONTAINS COUNT ; LD R2,FILEADDR ; R2 IS PTR TO FILE CHAR LDR R3,R2,#0 ; R3 CONTAINS CURRENT CHAR ; AGAIN ADD R4,R3,#-4 ; IS CHAR = BRz ALMOST_DONE ; IF YES, GOTO ALMOST_DONE ; NOT R3,R3 ADD R3,R3,#1 ADD R4,R3,R0 ; IS CHAR = INPUT BRnp AFTER_TALLY ; IF NO, SKIP OVER TALLY ADD R1,R1,#1 ; COUNT = COUNT + 1 ; AFTER_TALLY ADD R2,R2,#1 ; INCREMENT POINTER LDR R3,R2,#0 ; GET NEXT CHAR BRnzp AGAIN ; ALMOST_DONE LD R4,ASCII ADD R0,R1,R4 ; FORM ASCII CODE FOR THE COUNT DIGIT TRAP X21 ; OUTPUT THE COUNT TRAP X25 ; FILEADDR .BLKW 1 ; PLACE FOR THE POINTER TO BE STORED ASCII .FILL X30 ; ASCII TEMPLATE .END