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: 36 ADD R0, R0, R5 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:
- Specify the origin memory address of the previous code.
- Specify the hexadecimal value contained in the memory address 0003h.
- In line 19 of the previous code, what is the value contained in R1?
- In line 22 of the previous code, what is the value contained in R2?
- In line 25 of the previous code, what is the value contained in R3?
- In line 28 of the previous code, what is the value contained in R4?
- Specify the tag containing the code in charge of change some memory contents?
- Which are the modified memory address after executing this code?
- Taking the previous answer into account, please, specify the contents of these modified memory addresses.
- Could you write the formula resolved in the previous code?
And the answers:
- The program starts at memory address, given that we have specified explicitly in the code with the code:
- I include below, the memory mapping and values of registers (2, 3 and 4), considering we stop the execution at line ; with the following info we will be able to answer questions 2, 3, 4, 5 and 6:
- The tag in charge of storing new values in the memory, is named " ", more concretely the code:
MOV [R4], R0
stores the content of in the memory addresses contained in , , and (one address in each loop).
- Again a memory map helps to answer the questions 8 and 9:
Memory Address Value (Updated) 0006h 0005h 0007h 0008h 0008h 0009h
- The formula or operation performed by this program is:
|R2 points to 0000h||0000h||0001h|
|R3 points to 0003h||0003h||0005h|
|R4 points to 0006h||0006h||0001h|
Regarding the register 1, its content is , the first Byte (low 8 bits) is set to (i.e. 0003h) whereas the second Byte (high 8 bits) is set to (i.e. 0000h), resulting the following value .