0% found this document useful (0 votes)
8 views

Draw the map of this data segment

Uploaded by

hnam9607
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Draw the map of this data segment

Uploaded by

hnam9607
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

1.

Draw the map of this data segment

.data

arr16: .space 16

arr: .byte 'a','b','c'

st1: .asciz "abcd"

X1: .word 0xFFFFFFFF

st2: .ascii "efgh"

X2: .word 0xFFFFFFFF

st3: .asciz "1234"

X3: .word 0xFFFFFFFF

st4: .asciz "5678"

X4: .word 0xFFFFFFFF

2. Write the RISC-V assembly code equivalent to the following C statement. f = g + (h − 5)


3. Write the RISC-V assembly code equivalent to the below C statement. B[8] = A[i-j]
4. Reverse-compile the following RISC-V assembly code to the equivalent C code. Assume that the
variables f, g, h, i, and j are allocated at registers x5, x6, x7, x28, and x29, respectively, and the
base address of the arrays A and B are in registers x10 and x11. slli x30, x5, 2 add x30, x10, x30
slli x31, x6, 2 add x31, x11, x31 lw x5, 0(x30) addi x12, x30, 8 lw x30, 0(x12) add x30, x30, x5 lw
x30, 0(x31)

5. Find the format and the machine code of the following instruction: sw x5, 32(x30)

Format: S type

Machine Code:
6. Write a program to: l Input an integer X from console l Output to screen the appropriate string: -
“odd” if X is an odd number - “even” if X is an even number.
7.

1. Write a subprogram/function to: l Get an integer X as input argument l Output the absolute value
of X

❑ 2. Use the above function to write a program that reads an input integer from input console, then
calculate and display the absolute value of that integer.

❑ 3. Modify the above program so that it repeats the above process continuously until it reads the
value 0 from input console.
8. ❑ Write a program to read a positive value n from console, then calculate and print the sum of
all numbers from 1 to n.
❑ Implement the function of calculate sum as a procedure with below parameters: l a7: n
(upper boundary) l a0: return value of (1+2+..+n)

9. Develop a simple implementation of the strlen() function size_t strlen(const char *str). Write a
program to input a string (max of 255 chars), then print out its length

You might also like