# More about Assembly (Von Neumann simulator)

Today I've been in the campus with our computer science students in their first official test of the subject.

The test has been composed by 3 questions. With the second question we have tested the assembly language' knowledge of the students. In this case, rather than ask to students to implement a program from scratch, we have asked them about a provided code; concretely the following:

1	CONSTANT1 EQU 03h
2	CONSTANT2 EQU 00h
3
4	ORIGEN 00h
5
6	INICIO ini
7
8	.DATOS
9
10	     vector1 VALOR 0001h, 0002h, 0003h
11	     vector2 VALOR 0005h, 0004h, 0003h
12	     sortida VALOR 3 VECES 0001h
13
14	.CODIGO
15	ini:
16
17	     MOVL R1, CONSTANT1
18	     MOVH R1, CONSTANT2
19
20	     MOVL R2, BYTEBAJO DIRECCION vector1
21	     MOVH R2, BYTEALTO DIRECCION vector1
22
23	     MOVL R3, BYTEBAJO DIRECCION vector2
24	     MOVH R3, BYTEALTO DIRECCION vector2
25
26	     MOVL R4, BYTEBAJO DIRECCION sortida
27	     MOVH R4, BYTEALTO DIRECCION sortida
28
29	carrega:
30	     MOVL R0, 00h
31	     MOVH R0, 00h
32	     MOV R5, [R2]
33	     MOV R6, [R3]
34
35	multiplica:
37	     DEC R6
38	     BRNZ multiplica
39
40	desa:
41	     MOV [R4], R0
42	     INC R2
43	     INC R3
44	     INC R4
45	     DEC R1
46	     BRNZ carrega
47
48	final:
49	JMP -1
50	FIN


And the questions have been:

1. Specify the origin memory address of the previous code.
3. In line 19 of the previous code, what is the value contained in R1?
4. In line 22 of the previous code, what is the value contained in R2?
5. In line 25 of the previous code, what is the value contained in R3?
6. In line 28 of the previous code, what is the value contained in R4?
7. Specify the tag containing the code in charge of change some memory contents?
8. Which are the modified memory address after executing this code?
10. Could you write the formula resolved in the previous code?

1. The program starts at $0000h$ memory address, given that we have specified explicitly in the code with the code:
ORIGEN 00h

.

2. I include below, the memory mapping and values of registers (2, 3 and 4), considering we stop the execution at line $28$ ; with the following info we will be able to answer questions 2, 3, 4, 5 and 6:
3.  Register Memory Address Value R2 points to 0000h 0000h 0001h 0001h 0002h 0002h 0003h R3 points to 0003h 0003h 0005h 0004h 0004h 0005h 0003h R4 points to 0006h 0006h 0001h 0007h 0001h 0008h 0001h

Regarding the register 1, its content is $0003h$ , the first Byte (low 8 bits) is set to $CONSTANT1$ (i.e. 0003h) whereas the second Byte (high 8 bits) is set to $CONSTANT2$ (i.e. 0000h), resulting the following value $00000000h | 00000003h$ .

4. The tag in charge of storing new values in the memory, is named " $DESA$ ", more concretely the code:
MOV [R4], R0

stores the content of $R0$ in the memory addresses contained in $R4$ , $0006h$ , $0007h$ and $0008h$ (one address in each loop).

5. Again a memory map helps to answer the questions 8 and 9:
 Memory Address Value (Updated) 0006h 0005h 0007h 0008h 0008h 0009h
6. The formula or operation performed by this program is:
7. $SORTIDA[i] \;= \;VECTOR1[i] \;\cdot \;VECTOR2[i] \;\forall \;i \;\in \;]0,3]$

Posted in computer science, teaching