Electrical & Computer Engineering: Homework 10 Solutions |, Assignments of Computer Science

Typology: Assignments

2019/2020

Uploaded on 06/15/2020

ubimaiorminorcessat
ubimaiorminorcessat 🇺🇸

4.4

(17)

225 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
University of Florida EEL 3701 Dr. Eric M. Schwartz
Department of Electrical & Computer Engineering
Page 1/1 Homework 10 Solutions
1. Here is a short program that shows all addressing modes:
We are given a table of student's test scores where there are three scores in a semester per student.
Unfortunately, the person who entered the grades put them in the wrong order. They presently are in the
following order. Student #1 test #2/test #3/test #1, Student #2 test #2/test #3/test #1… Student #200 test
#2/test #3/test #1. We would like them to be in the following order. Student #1 test #1/test #2/test #3,
Student #2 test #1/test #2/test #3… Student #200 test #1/test #2/test #3. Assume all scores start at
1000H (SRAM).
N EQU 200
TABLE EQU $1000
NEG1 EQU %11111111 ; $FF
ORG $1800 ; temporary data area
TEMP DS.B 1
COUNT DS.B 1
ORG $0
LDAA #N
STAA COUNT
LDX #TABLE ; ptr to top of table (immediate addressing)
Loop_pt LDAB 0,X ; get test #2 score (indexed addressing)
LDAA 1,X ; get test #3 score (indexed addressing)
STAA TEMP ; save test #3 score in temp area (extended)
LDAA 2,X ; get test #1 score (indexed)
Re_order_data
STAA 0,X ; store test #1 score (indexed)
STAB 1,X ; store test #2 score (indexed)
LDAA TEMP ; get test #3 score (extended)
STAA 2,X ; store test #3 score (indexed)
Check_counter
LDAA COUNT ; retrieve count (extended)
LDAB #NEG1 ; decrement counter (immediate)
SUM_BA ; count = count -1 (inherent)
* ABA ; equivalent to SUM_BA on 68HC11/12
BEQ END ; if count = 0 then end (branch addressing)
STAA COUNT ; save count (extended)
INX ; inc ptr (inherent)
INX ; inc ptr (inherent)
INX ; inc ptr (inherent)
BNE Loop_pt ; if count != 0 then loop (branch addressing)
END BEQ END ; something to do (branch addressing)
pf3
pf4
pf5

Partial preview of the text

Download Electrical & Computer Engineering: Homework 10 Solutions | and more Assignments Computer Science in PDF only on Docsity!

Department of Electrical & Computer Engineering

Page 1/1 Homework 10 Solutions

  1. Here is a short program that shows all addressing modes:

We are given a table of student's test scores where there are three scores in a semester per student. Unfortunately, the person who entered the grades put them in the wrong order. They presently are in the following order. Student #1 test #2/test #3/test #1, Student #2 test #2/test #3/test #1… Student #200 test #2/test #3/test #1. We would like them to be in the following order. Student #1 test #1/test #2/test #3, Student #2 test #1/test #2/test #3… Student #200 test #1/test #2/test #3. Assume all scores start at 1000H (SRAM).

N EQU 200 TABLE EQU $ NEG1 EQU %11111111 ; $FF

ORG $1800 ; temporary data area TEMP DS.B 1 COUNT DS.B 1

ORG $ LDAA #N STAA COUNT LDX #TABLE ; ptr to top of table (immediate addressing) Loop_pt LDAB 0,X ; get test #2 score (indexed addressing) LDAA 1,X ; get test #3 score (indexed addressing) STAA TEMP ; save test #3 score in temp area (extended) LDAA 2,X ; get test #1 score (indexed) Re_order_data STAA 0,X ; store test #1 score (indexed) STAB 1,X ; store test #2 score (indexed) LDAA TEMP ; get test #3 score (extended) STAA 2,X ; store test #3 score (indexed) Check_counter LDAA COUNT ; retrieve count (extended) LDAB #NEG1 ; decrement counter (immediate) SUM_BA ; count = count -1 (inherent)

  • ABA ; equivalent to SUM_BA on 68HC11/ BEQ END ; if count = 0 then end (branch addressing) STAA COUNT ; save count (extended) INX ; inc ptr (inherent) INX ; inc ptr (inherent) INX ; inc ptr (inherent) BNE Loop_pt ; if count != 0 then loop (branch addressing) END BEQ END ; something to do (branch addressing)

Department of Electrical & Computer Engineering

Page 2/1 Homework 10 Solutions

  1. a) Here is the hand assembly (shown in two different formats)

This code grabs a number from Table #1 @ $1100 and a number from Table #2 @ $1110 and then computes an average value which is then stored in a Table #3, starting at $1120.

b) This process is repeated 16 ($10) decimal times. c) We must save the count in a temporary memory location because the A register is corrupted inside the loop that retrieves the data and computes the average value.

Address (Hex)

Data (Hex) Instructions 0 08 LDX^ #$ 1 00 2 11 3 02 LDAA^ #$ 4 10 5 06 STAA^ $ 6 00 7 12 8 0C LOOP:^ LDAA 0,X 9 00 A 0E LDAB^ $10,X B 10 C 15 SUM_AB D 1F SHFB_R E 12 STAB $20,X F 20 10 30 INX 11 03 LDAB^ #$FF 12 FF 13 04 LDAA^ $ 14 00 15 12 16 14 SUM_BA 17 20 BEQ^ DONE 18 1E 19 06 STAA^ $ 1A 00 1B 12 1C 21 BNE LOOP 1D 08 1E 20 DONE:^ BEQ^ DONE 1F 1E

Address (Hex)

Data (Hex) Instructions 0 08 00 11^ LDX^ #$ 3 02 10^ LDAA^ #$ 5 06 00 12^ STAA^ $ 8 0C 00^ LOOP:^ LDAA^ 0,X A 0E 10^ LDAB^ $10,X C 15 SUM_AB D 1F SHFB_R E 12 20^ STAB^ $20,X 10 30 INX 11 03 FF LDAB #$FF 13 04 00 12^ LDAA^ $ 16 14 SUM_BA 17 20 1E^ BEQ^ DONE 19 06 00 12^ STAA^ $ 1C 21 08^ BNE^ LOOP 1E 20 1E^ DONE:^ BEQ^ DONE

Department of Electrical & Computer Engineering

Page 4/1 Homework 10 Solutions

  1. Here is the program that corresponds to the machine code listed in problem #3:

ORG $ STAA $1400 ; temporarily store the A reg value COMA ; /A AND_BA ; /AB STAA $1401 ; save /AB for future use LDAA $1400 ; restore original A reg value COMB ; /B AND_BA ; A /B TAB LDAA $1401 ; retrieve /AB OR_BA ; (A/B) + (/AB)

This code performs the exclusive or of registers A and B (A xor B = A/B + /AB) and then returns this value in register A. Two temporary locations are required, 1400H and 1401H.

  1. Code to count the number of (decimal) 37’s in memory from $1000-$107F:

  • The final result is in Num37s and is also passed to the A register. If this result is zero (i.e. no 37s found),
  • the program will crash. Why?

NUM EQU $7F+1 ; = $ Neg1 EQU $FF Neg37 EQU $DB ; -37 = -$25 = -(%0010 0101) Table EQU $

  • ; -(%0010 0101) => %1101 1010 + %1 = %1101 1011 = $DB ORG $1100 ; The below program uses these temporary locations that are reserved in memory Num37s DS.B 1 ; Keep track of the number of 37s found LoopCnt DS.B 1 ; Loop counter
  • Neg37 DS.B 1 ; Holds -37 value used to test if the current data is 37 ORG $ LDAA # STAA Num37s ; Initialize the count of 37’s found to zero LDAA #NUM ; Initialize the loop counter (how many times the loop is executed) STAA LoopCnt ; ... LDX #Table ; Initialize table pointer to point to the beginning of the table TOP LDAA 0,X ; Get first table value LDAB #Neg37 ; Get - SUM_BA ; Add table value to –37. If result is zero, table value was 37. BNE SKIP_INC ; If result is not zero, the table value was not 37, so don’t increment. LDAA Num37s ; increment the number of $37s count value LDAB # SUM_AB STAB Num37s SKIP_INC LDAA LoopCnt LDAB #Neg1 ; Decrement loop counter SUM_BA ; ... BEQ DONE STAA LoopCnt INX ; Increment the data pointer BNE TOP DONE LDAA Num37s WAIT BNE WAIT BEQ WAIT

Department of Electrical & Computer Engineering

Page 5/1 Homework 10 Solutions

  1. BRA $addr

Q5:0 IR5:0 Z N D5:0 MSA MSB MSC IR_LD RW PMXY SEL PC_LD M_LD X_LD Y_LD XD YD 000001 110010 - - 110100 01 10 0000 0 1 1000 00 00 00 00 00 0 0 110100 ------ - - 000000 01 10 0000 0 1 0000 00 10 00 00 00 0 0

IR_LD

IR_5:

$addr => PCL

INC_PC