-1

I am trying to store a 32 bit immediate value in a riscv memory location.The corresponding code is

lui x13,0x12345
addi x13,x13,0x678   // 32 bit value- 12345678
lui x11, 0x1c010     // address location 1c01000
sw x13,x11

The problem I am facing is during simulation 32 bit value is not found in the address location(1c01000). Address location shows only 1 byte of the given data(78)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
RISCV
  • 15
  • 6
  • The value shown in 1c01000 location is 78787878 – RISCV Jul 03 '20 at 06:34
  • Are you sure there is (simulated) memory at that address? Try it at a more "usual" address, e.g. 0x10000000 or 0x10010000, to see if that works as expected. Otherwise, declare the data: `.data ... label: .word 0 ... .text ... la x11, label; sw x13,(x11)`. This way the data should get a valid memory address. – Erik Eidt Jul 03 '20 at 16:00
  • 1
    Also, there is a typo in your example, should read `sw x13,(x11)` -or- `sw x13,0(x11)`. What assembler & simulator are you using? – Erik Eidt Jul 03 '20 at 16:05
  • sw x13,(x11) simulator using is Gtkwave – RISCV Jul 04 '20 at 06:48
  • I checked the memory banks separately 78 is copied in all the four banks, memory write is not done at that time. – RISCV Jul 10 '20 at 05:07

1 Answers1

1

RISC-V is byte-addressable. If you only checked the one byte at that address, obviously it will contain only 1 byte of the 4-byte value.

You need to check the whole 32-bit word at that address, or the 4 bytes 1c01000 .. 1c01003 separately.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • I checked the memory banks separately 78 is copied in all the four banks, memory write is not done at that time..Is there any error with my program? – RISCV Jul 10 '20 at 05:11