RISCV instructions












0















I am new to riscv and I am confused between la and lw.



I know that la stands for load address and lw stands for load word. If address of VAL is 0x100 and data value of VAL is 0x11 should x3 stores 0x100 and x4 stores 0x11?



la x7, VAL
sw x3, 0(x7)
lw x4, VAL
bne x4, x3









share|improve this question





























    0















    I am new to riscv and I am confused between la and lw.



    I know that la stands for load address and lw stands for load word. If address of VAL is 0x100 and data value of VAL is 0x11 should x3 stores 0x100 and x4 stores 0x11?



    la x7, VAL
    sw x3, 0(x7)
    lw x4, VAL
    bne x4, x3









    share|improve this question



























      0












      0








      0








      I am new to riscv and I am confused between la and lw.



      I know that la stands for load address and lw stands for load word. If address of VAL is 0x100 and data value of VAL is 0x11 should x3 stores 0x100 and x4 stores 0x11?



      la x7, VAL
      sw x3, 0(x7)
      lw x4, VAL
      bne x4, x3









      share|improve this question
















      I am new to riscv and I am confused between la and lw.



      I know that la stands for load address and lw stands for load word. If address of VAL is 0x100 and data value of VAL is 0x11 should x3 stores 0x100 and x4 stores 0x11?



      la x7, VAL
      sw x3, 0(x7)
      lw x4, VAL
      bne x4, x3






      riscv






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 10:37









      FabienM

      1,116825




      1,116825










      asked Nov 21 '18 at 5:17









      YoungBin JoYoungBin Jo

      92




      92
























          2 Answers
          2






          active

          oldest

          votes


















          1














          la computes an pointer-sized effective address, but does not perform any memory access.  The effective address itself is what is loaded into x7.



          (Also note that la is a pseudo instruction that may expand into two instructions, depending on VAL — none the less, the sequence computes an effective address and that is its result (no memory access is performed).)



          lw also computes an effective address; however, it uses the effective address in a word-sized memory access, and the result of that memory access is the value loaded into x4.



          lb would do the same as lw except that the memory access is byte-sized.





          As far as your code sequence goes, the value that was in x3 (which cannot be determined from your code snippet) will be stored into memory at locations 0x100-0x103 (this is a word-sized store).



          The lw will reload the value that was written by the sw.  (Note that the lw in this case may also expand to multiple instructions depending on VAL, whereas the sw is a single instruction regardless of VAL.)



          The bne (though missing a target label) will not branch.






          share|improve this answer































            1














            la t0, SYMBOL is an assembler pesudo instruction that puts the address of SYMBOL into t0. Depending on the addressing mode, it expands to something like



            lui t0, SYMBOL[31:12]
            addi t0, t0, SYMBOL[11:0]


            where SYMBOL[31:12] is the high bits of SYMBOL, and SYMBOL[11:0] is the low bits of SYMBOL -- these aren't valid assembler syntax, and there's some tricks to play with sign extension to get this exactly correct.



            lw t0, SYMBOL is an assembler pseudo instruction that puts the value of memory at the address SYMBOL into t0. Depending on the addressing mode, it expands to something like



            lui t0, SYMBOL[31:12]
            lw t0, SYMBOL[11:0](t0)


            Specifically the difference is that lw performs a load from memory, while la just generates an address. The sequence



            la t0, SYMBOL
            lw t0, 0(0)


            is functionally equivalent to



            lw t0, SYMBOL


            but takes an extra instruction, specifically



            lui t0, SYMBOL[31:12]
            addi t0, t0, SYMBOL[11:0]
            lw t0, 0(t0)


            vs



            lui t0, SYMBOL[31:12]
            lw t0, SYMBOL[11:0](t0)


            This should all be documentation in the RISC-V Assembly Programmer's Manual, but that is always a work in progress. If you find that's lacking then feel free to submit a patch or open an issue.






            share|improve this answer























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405655%2friscv-instructions%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              1














              la computes an pointer-sized effective address, but does not perform any memory access.  The effective address itself is what is loaded into x7.



              (Also note that la is a pseudo instruction that may expand into two instructions, depending on VAL — none the less, the sequence computes an effective address and that is its result (no memory access is performed).)



              lw also computes an effective address; however, it uses the effective address in a word-sized memory access, and the result of that memory access is the value loaded into x4.



              lb would do the same as lw except that the memory access is byte-sized.





              As far as your code sequence goes, the value that was in x3 (which cannot be determined from your code snippet) will be stored into memory at locations 0x100-0x103 (this is a word-sized store).



              The lw will reload the value that was written by the sw.  (Note that the lw in this case may also expand to multiple instructions depending on VAL, whereas the sw is a single instruction regardless of VAL.)



              The bne (though missing a target label) will not branch.






              share|improve this answer




























                1














                la computes an pointer-sized effective address, but does not perform any memory access.  The effective address itself is what is loaded into x7.



                (Also note that la is a pseudo instruction that may expand into two instructions, depending on VAL — none the less, the sequence computes an effective address and that is its result (no memory access is performed).)



                lw also computes an effective address; however, it uses the effective address in a word-sized memory access, and the result of that memory access is the value loaded into x4.



                lb would do the same as lw except that the memory access is byte-sized.





                As far as your code sequence goes, the value that was in x3 (which cannot be determined from your code snippet) will be stored into memory at locations 0x100-0x103 (this is a word-sized store).



                The lw will reload the value that was written by the sw.  (Note that the lw in this case may also expand to multiple instructions depending on VAL, whereas the sw is a single instruction regardless of VAL.)



                The bne (though missing a target label) will not branch.






                share|improve this answer


























                  1












                  1








                  1







                  la computes an pointer-sized effective address, but does not perform any memory access.  The effective address itself is what is loaded into x7.



                  (Also note that la is a pseudo instruction that may expand into two instructions, depending on VAL — none the less, the sequence computes an effective address and that is its result (no memory access is performed).)



                  lw also computes an effective address; however, it uses the effective address in a word-sized memory access, and the result of that memory access is the value loaded into x4.



                  lb would do the same as lw except that the memory access is byte-sized.





                  As far as your code sequence goes, the value that was in x3 (which cannot be determined from your code snippet) will be stored into memory at locations 0x100-0x103 (this is a word-sized store).



                  The lw will reload the value that was written by the sw.  (Note that the lw in this case may also expand to multiple instructions depending on VAL, whereas the sw is a single instruction regardless of VAL.)



                  The bne (though missing a target label) will not branch.






                  share|improve this answer













                  la computes an pointer-sized effective address, but does not perform any memory access.  The effective address itself is what is loaded into x7.



                  (Also note that la is a pseudo instruction that may expand into two instructions, depending on VAL — none the less, the sequence computes an effective address and that is its result (no memory access is performed).)



                  lw also computes an effective address; however, it uses the effective address in a word-sized memory access, and the result of that memory access is the value loaded into x4.



                  lb would do the same as lw except that the memory access is byte-sized.





                  As far as your code sequence goes, the value that was in x3 (which cannot be determined from your code snippet) will be stored into memory at locations 0x100-0x103 (this is a word-sized store).



                  The lw will reload the value that was written by the sw.  (Note that the lw in this case may also expand to multiple instructions depending on VAL, whereas the sw is a single instruction regardless of VAL.)



                  The bne (though missing a target label) will not branch.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 16:26









                  Erik EidtErik Eidt

                  2,42011723




                  2,42011723

























                      1














                      la t0, SYMBOL is an assembler pesudo instruction that puts the address of SYMBOL into t0. Depending on the addressing mode, it expands to something like



                      lui t0, SYMBOL[31:12]
                      addi t0, t0, SYMBOL[11:0]


                      where SYMBOL[31:12] is the high bits of SYMBOL, and SYMBOL[11:0] is the low bits of SYMBOL -- these aren't valid assembler syntax, and there's some tricks to play with sign extension to get this exactly correct.



                      lw t0, SYMBOL is an assembler pseudo instruction that puts the value of memory at the address SYMBOL into t0. Depending on the addressing mode, it expands to something like



                      lui t0, SYMBOL[31:12]
                      lw t0, SYMBOL[11:0](t0)


                      Specifically the difference is that lw performs a load from memory, while la just generates an address. The sequence



                      la t0, SYMBOL
                      lw t0, 0(0)


                      is functionally equivalent to



                      lw t0, SYMBOL


                      but takes an extra instruction, specifically



                      lui t0, SYMBOL[31:12]
                      addi t0, t0, SYMBOL[11:0]
                      lw t0, 0(t0)


                      vs



                      lui t0, SYMBOL[31:12]
                      lw t0, SYMBOL[11:0](t0)


                      This should all be documentation in the RISC-V Assembly Programmer's Manual, but that is always a work in progress. If you find that's lacking then feel free to submit a patch or open an issue.






                      share|improve this answer




























                        1














                        la t0, SYMBOL is an assembler pesudo instruction that puts the address of SYMBOL into t0. Depending on the addressing mode, it expands to something like



                        lui t0, SYMBOL[31:12]
                        addi t0, t0, SYMBOL[11:0]


                        where SYMBOL[31:12] is the high bits of SYMBOL, and SYMBOL[11:0] is the low bits of SYMBOL -- these aren't valid assembler syntax, and there's some tricks to play with sign extension to get this exactly correct.



                        lw t0, SYMBOL is an assembler pseudo instruction that puts the value of memory at the address SYMBOL into t0. Depending on the addressing mode, it expands to something like



                        lui t0, SYMBOL[31:12]
                        lw t0, SYMBOL[11:0](t0)


                        Specifically the difference is that lw performs a load from memory, while la just generates an address. The sequence



                        la t0, SYMBOL
                        lw t0, 0(0)


                        is functionally equivalent to



                        lw t0, SYMBOL


                        but takes an extra instruction, specifically



                        lui t0, SYMBOL[31:12]
                        addi t0, t0, SYMBOL[11:0]
                        lw t0, 0(t0)


                        vs



                        lui t0, SYMBOL[31:12]
                        lw t0, SYMBOL[11:0](t0)


                        This should all be documentation in the RISC-V Assembly Programmer's Manual, but that is always a work in progress. If you find that's lacking then feel free to submit a patch or open an issue.






                        share|improve this answer


























                          1












                          1








                          1







                          la t0, SYMBOL is an assembler pesudo instruction that puts the address of SYMBOL into t0. Depending on the addressing mode, it expands to something like



                          lui t0, SYMBOL[31:12]
                          addi t0, t0, SYMBOL[11:0]


                          where SYMBOL[31:12] is the high bits of SYMBOL, and SYMBOL[11:0] is the low bits of SYMBOL -- these aren't valid assembler syntax, and there's some tricks to play with sign extension to get this exactly correct.



                          lw t0, SYMBOL is an assembler pseudo instruction that puts the value of memory at the address SYMBOL into t0. Depending on the addressing mode, it expands to something like



                          lui t0, SYMBOL[31:12]
                          lw t0, SYMBOL[11:0](t0)


                          Specifically the difference is that lw performs a load from memory, while la just generates an address. The sequence



                          la t0, SYMBOL
                          lw t0, 0(0)


                          is functionally equivalent to



                          lw t0, SYMBOL


                          but takes an extra instruction, specifically



                          lui t0, SYMBOL[31:12]
                          addi t0, t0, SYMBOL[11:0]
                          lw t0, 0(t0)


                          vs



                          lui t0, SYMBOL[31:12]
                          lw t0, SYMBOL[11:0](t0)


                          This should all be documentation in the RISC-V Assembly Programmer's Manual, but that is always a work in progress. If you find that's lacking then feel free to submit a patch or open an issue.






                          share|improve this answer













                          la t0, SYMBOL is an assembler pesudo instruction that puts the address of SYMBOL into t0. Depending on the addressing mode, it expands to something like



                          lui t0, SYMBOL[31:12]
                          addi t0, t0, SYMBOL[11:0]


                          where SYMBOL[31:12] is the high bits of SYMBOL, and SYMBOL[11:0] is the low bits of SYMBOL -- these aren't valid assembler syntax, and there's some tricks to play with sign extension to get this exactly correct.



                          lw t0, SYMBOL is an assembler pseudo instruction that puts the value of memory at the address SYMBOL into t0. Depending on the addressing mode, it expands to something like



                          lui t0, SYMBOL[31:12]
                          lw t0, SYMBOL[11:0](t0)


                          Specifically the difference is that lw performs a load from memory, while la just generates an address. The sequence



                          la t0, SYMBOL
                          lw t0, 0(0)


                          is functionally equivalent to



                          lw t0, SYMBOL


                          but takes an extra instruction, specifically



                          lui t0, SYMBOL[31:12]
                          addi t0, t0, SYMBOL[11:0]
                          lw t0, 0(t0)


                          vs



                          lui t0, SYMBOL[31:12]
                          lw t0, SYMBOL[11:0](t0)


                          This should all be documentation in the RISC-V Assembly Programmer's Manual, but that is always a work in progress. If you find that's lacking then feel free to submit a patch or open an issue.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 2 at 18:58









                          Palmer DabbeltPalmer Dabbelt

                          4005




                          4005






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405655%2friscv-instructions%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              這個網誌中的熱門文章

                              Tangent Lines Diagram Along Smooth Curve

                              Yusuf al-Mu'taman ibn Hud

                              Zucchini