Giter Club home page Giter Club logo

Comments (3)

jim-wilson avatar jim-wilson commented on August 23, 2024 3

Perhaps you meant to use jal? jal takes a 20-bit offset. jalr takes a reg plus 12-bit offset. We don't allow symbols with jalr as it isn't useful, this would be x0 as the base register plus a 12-bit offset which can only work if the target is in the low 4KB of memory which is rather unlikely. jal with a symbol is allowed and gives a 1MB range which is enough to be useful.

If you really want jalr, you can use
jalr ra, %lo(puts)(x0)

The standard way to do a call is to use the call macro
call puts
This expands to
c: 00000097 auipc ra,0x0
c: R_RISCV_CALL puts
c: R_RISCV_RELAX ABS
10: 000080e7 jalr ra # c <main+0xc>
where the R_RISCV_CALL reloc puts the high part of the address offset in the auipc and the low part in the jalr, and the linker will relax this to a jal if in range. We unfortunately don't have assembler syntax to generate this directly, so you have to use the call macro. There is also a tail macro for tail calls.

from riscv-asm-manual.

jim-wilson avatar jim-wilson commented on August 23, 2024 1

But note that
jalr ra, %lo(puts)(x0)
will silently fail if puts is not in the low 4KB of memory.

from riscv-asm-manual.

quantrpeter avatar quantrpeter commented on August 23, 2024

thanks @jim-wilson

from riscv-asm-manual.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.