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:

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

And the questions have been:

  1. Specify the origin memory address of the previous code.
  2. Specify the hexadecimal value contained in the memory address 0003h.
  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?
  9. Taking the previous answer into account, please, specify the contents of these modified memory addresses.
  10. Could you write the formula resolved in the previous code?

And the answers:

  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

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>