[go: up one dir, main page]

100% found this document useful (1 vote)
110 views4 pages

Assembly Language Worksheet 1

Computer Science A level Aqa worksheet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
110 views4 pages

Assembly Language Worksheet 1

Computer Science A level Aqa worksheet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Worksheet 1 Assembly language

Unit 5 Computer organisation

Worksheet 1 Assembly language

Use the instructions in Table 1 on the next page for all questions on this worksheet

Task 1
1. A positive number is held in memory location 201. Write assembly code instructions which
put the negative of the number in location 202. ADD [4]

2. Write assembly code instructions to take three numbers held in locations 201, 202 and 203
and store them back in the same locations in reverse order. [4]
ADD
3. Three numbers are held in locations 201, 202 and 203. Write assembly code instructions to
store the maximum of the three numbers in location 300. [5]

4. Assume that numbers can be input by a user into Register 0 using the instruction
INP R0
(a) Ten numbers are input by the user. Write assembly code instructions to add the ten
numbers as they are input and store the result in location 300. [5]
(b) Ten integers are input by the user. Write assembly code instructions to count the
number of integers that are greater than or equal to 30. The result should be stored in
location 300. [6]

Task 2
1. Write assembly code instructions to find whether a number held in location 200 is odd or
even. [5]

2. A bit pattern held in R0 represents 8 switches numbered 1 to 8 (left to right).

(a) Write assembly code instructions to initialise the switches to zero, and then turn on
switches 1,3,5 and 7. [2]

(b) Assume you do not know the state of the switches in R0. Write an assembly code
instruction to turn off any switches that are on, and vice versa. [1]

3. What will be the effect of performing an XOR operation on an operand with itself [1]
Give an example. [1]

Task 3
1. Assume R0 contains an 8-bit positive integer. Using logical shifts, compare and branch
operations, write assembly code statements to branch to LABEL1 if the integer represents
an even number, otherwise continue to the next statement. [5]
Test your program by tracing the contents of R0 and any other registers used. [3]
Can you think of another way of testing whether the number is even? [2]

1
Worksheet 1 Assembly language
Unit 5 Computer organisation
Table 1: Assembly language instructions

Load the value stored in the memory location specified by


LDR Rd, <memory ref>
<memory ref> into register d.
Store the value that is in register d into the memory
STR Rd, <memory ref>
location specified by <memory ref>.
Add the value specified in <operand> to the value in
ADD Rd, Rn, <operand>
register n and store the result in register d.
Subtract the value specified by <operand> from the value
SUB Rd, Rn, <operand>
in register n and store the result in register d.
MOV Rd, <operand> Copy the value specified by <operand> into register d.
Compare the value stored in register n with the value
CMP Rn, <operand>
specified by <operand>.
Always branch to the instruction at position <label> in the
B <label>
program.
Conditionally branch to the instruction at position <label>
in the program if the last comparison met the criteria
specified by the <condition>. Possible values for
B<condition> <label>
<condition> and their meaning are:
EQ: Equal to, NE: Not equal to, GT: Greater than, LT:
Less than.
Perform a bitwise logical AND operation between the value
AND Rd, Rn, <operand> in register n and the value specified by <operand> and
store the result in register d.
Perform a bitwise logical OR operation between the value
ORR Rd, Rn, <operand> in register n and the value specified by <operand> and
store the result in register d.
Perform a bitwise logical exclusive or (XOR) operation
EOR Rd, Rn, <operand> between the value in register n and the value specified by
<operand> and store the result in register d.
Perform a bitwise logical NOT operation on the value
MVN Rd, <operand>
specified by <operand> and store the result in register d.
Logically shift left the value stored in register n by the
LSL Rd, Rn, <operand> number of bits specified by <operand> and store the
result in register d.
Logically shift right the value stored in register n by the
LSR Rd, Rn, <operand> number of bits specified by <operand> and store the
result in register d.
HALT Stops the execution of the program.

<operand> can be interpreted in two different ways, depending upon whether the first symbol
is a # or an R:

 # – Use the decimal value specified after the #, e.g. #25 means use the decimal value 25.
 Rm – Use the value stored in register m, e.g. R6 means use the value stored in register 6.
The available general purpose registers that the programmer can use are numbered 0 to 7.

2
Worksheet 1 Assembly language
Unit 5 Computer organisation
The assembly code instruction formats in Table 1 are used in the questions in this
homework.

1. Examine the following assembly code.


LDR R1, 101
LABEL1
SUB R1, R1, 102
CMP R1, #0
BGT LABEL1
BEQ LABEL2
ADD R1, R1, 102
LABEL2
STR R1, 103
(a) If memory location 101 contains the number 23 and memory location 102 contains the
number 7, what will be the contents of memory location 103 after the execution of the
code? (Tip: Draw a trace table!) [2]

(b) Explain what the instruction SUB R1, 102 does the first time round the loop starting
at LABEL1.
[1]

(c) How many times is the loop performed? [1]

(d) What does the program do? [1]

2. (a) Write assembly code instructions to compare the contents of register 1 and register 2
and branch to LABEL1 if they are equal. [2]

(b) Explain with the aid of examples the difference between immediate and direct
addressing. [2]

3
Worksheet 1 Assembly language
Unit 5 Computer organisation
3. Write the assembly code instructions which are equivalent to the following high-level code.
Comment each line of code.
x  0
WHILE x < 1000
x = x + 1
ENDWHILE [6]

4. In a particular computer, characters are represented by 8-bit patterns. The codes for
uppercase letters are from 0100 0001 for A to 0101 1010 for Z. The codes for lowercase
letters are from 0110 0001 for a to 0111 1010 for z. Give an appropriate mask and logical
operation which will:
(a) change any uppercase letter to its lowercase equivalent [2]

(b) change any lowercase letter to its uppercase equivalent [2]

5. An 8-bit word contains the bit pattern 10110010.


State the contents of the word after a logical right shift of 3 bits. [1]

You might also like