Kingcom / armips

An assembler for various ARM and MIPS platforms. Builds available at http://buildbot.orphis.net/armips/
MIT License
363 stars 77 forks source link

Allow data address as load/store offset #193

Closed clbr closed 2 years ago

clbr commented 4 years ago
.rsp

.create "test.bin", 0
ldv v1, buf(r0)
lb r1, buf(r0)
.close

.create "data.bin", 0
buf: .fill 16
.close

Both of these loads error out. When the address of a memory area fits into the signed 16-bit offset, the assembler should allow this pattern. I'm aware the load macros circumvent this for the standard loads (lb r1, buf), but not for RSP's vector loads.

This is a recommended pattern on the RSP, because with its 4kb memory addresses always fit into the offset.

clbr commented 4 years ago

I found a workaround:

lb r1, org(buf)(r0)

happens to work. However it's painful to write, so I'd still like native support.

sp1187 commented 4 years ago

This bug is an unfortunate effect of a syntax conflict between MIPS base/offset syntax and expression functions. You don't need the org(buf) in the workaround, just (buf)(r0) will do.

clbr commented 4 years ago

Seems the parser could still handle this, if increasing complexity a bit. Only in this specific position in loads/stores, if there is no function by that name, check data labels.

Kingcom commented 4 years ago

This is indeed an unfortunate side effect. The only way around it is to determine the type of the expression based on whether the identifier is a function or not... which is very annoying, as it makes the grammar even more context sensitive than it already is... but it wouldn't be too difficult to achieve.