Quiz 2 for Microcomputer Systems | ECE 3120, Quizzes of Microcomputers

Material Type: Quiz; Class: Microcomputer Systems; Subject: ECE Elect & Computer Engr; University: Tennessee Tech University; Term: Fall 2000;

Typology: Quizzes

Pre 2010

Uploaded on 07/30/2009

koofers-user-jr6
koofers-user-jr6 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Quiz 2
ECE-3120: Fall ‘08
1) Write an instruction sequence to add two 16 bit numbers stored at $2000-$2001 and
$2002~$2003 and subtract the 16 bit number stored at $1000 from the sum. Store
the result in $$2100
org $1000 ;starting address of the program
ldd $2000 ;DÅm[$2000]
addd $2002 ;DÅm[$2002]
subd $1000 ;DÅm[$1000]
std $2100 ;DÅm[$2100]
2) Write a sequence of instructions to compute the sum of N signed 8-bit numbers stored
at memory locations $1000 and store the result in $2000
N equ 5 ;array count
org $1000 ;starting address of the array
array: db 1,2,3,4,5
org $2000 ;starting address of the array
sum: rmb 1 ;array sum assuming we need just 1 byte
i: rmb 1 ;array index
org $1500 ;starting address of the program
ldaa #0
staa i ;initialize loop (array) index to 0
staa sum ;initialize sum to 0
loop: ldab i
cmpb #N ;is I = N?
beq done ;if done, then branch
ldx #array ;use index register X as a pointer to the array
abx ;compute the address of array[i]
ldab 0,x ;place array[i] in B
ldy sum ;place sum in Y
aby ;sumÅsum+array[i]
sty sum ;update sum
inc i ;increment loop counter by 1
bra loop
done: swi ;return to D-Bug12 monitor
end
pf2

Partial preview of the text

Download Quiz 2 for Microcomputer Systems | ECE 3120 and more Quizzes Microcomputers in PDF only on Docsity!

Quiz 2 ECE-3120: Fall ‘

  1. Write an instruction sequence to add two 16 bit numbers stored at $2000-$2001 and $2002~$2003 and subtract the 16 bit number stored at $1000 from the sum. Store the result in $$

org $1000 ;starting address of the program ldd $2000 ;DÅm[$2000] addd $2002 ;DÅm[$2002] subd $1000 ;DÅm[$1000] std $2100 ;DÅm[$2100]

  1. Write a sequence of instructions to compute the sum of N signed 8-bit numbers stored at memory locations $1000 and store the result in $

N equ 5 ;array count org $1000 ;starting address of the array array: db 1,2,3,4, org $2000 ;starting address of the array sum: rmb 1 ;array sum assuming we need just 1 byte i: rmb 1 ;array index org $1500 ;starting address of the program ldaa # staa i ;initialize loop (array) index to 0 staa sum ;initialize sum to 0 loop: ldab i cmpb #N ;is I = N? beq done ;if done, then branch ldx #array ;use index register X as a pointer to the array abx ;compute the address of array[i] ldab 0,x ;place array[i] in B ldy sum ;place sum in Y aby ;sumÅsum+array[i] sty sum ;update sum inc i ;increment loop counter by 1 bra loop done: swi ;return to D-Bug12 monitor end

  1. Write a sequence of instruction to toggle the upper four bits of an 8-bit number stored at memory location $1000. Also write instructions to clear the lower four bits of the same number [e.g:- 10101010 Æ 01010000]

ldaa $1000 ;DÅm[$1000], loading the number to be ;manipulated in D eora #$F0 ;Toggles upper 4 bits in A anda #$F0 ;clears the lower 4 bits in A

Logic

Example : AÅ 10111100 ldaa $1000 ;AÅ 10111100 eora #$F0 ;A XOR $F0 Æ 10111100 ; XOR 11110000 Æ 01001100 So after eora A Å01001100 (finished toggle part) anda #$F0 ;A AND $F) Æ 01001100 ; AND Æ 11110000 Æ 01000000 So after anda AÅ01000000 (finished clearing lower 4 bits)