4 ms·
I see this a lot reverse engineering programs made for an older ISA from the 90s called SH4. Its a 32-bit RISC that uses 16-bit instructions[1] and is therefor
by snickerbockers 3y ago
I see this a lot reverse engineering programs made for an older ISA from the 90s called SH4. Its a 32-bit RISC that uses 16-bit instructions[1] and is therefore unable to load more than 8 bits of arbitrary immediate data (sometimes 12 but usually 8) into a register without spreading the operation over several instructions so most functions will have large blocks of data at the end (and sometimes even in the middle, because it needs to get a pointer to the data by offset from the PC and the instruction format is limited to 8 bit offsets) where they load in constant values and pointers. I'm pretty sure gcc even does this. I see it so often it never occurred to me this would be unusual on other CPUs.
[1] doubles the effective size of the instruction cache and also makes dual pipelines easier to implement because they can both fetch from the same bus at the same time. Legend has it that this was successful enough to be the inspiration behind thumb mode on ARM, which is also a 32 bit ISA with 16 bit instructions.
- projektfu 3y agoIt's 8086's history as a descendant of a limited 8-bit ISA that made it lack PC-relative addressing. I'm not sure why it was never added in all of its iterations until x64. Other ISAs from the minicomputer age (PDP-11) and their descendants and inspirations (H8, 68k) had it. Zilog added PC relative loads and address calculations to the Z8000, and it's a generally popular form now in x64. The Unix V6 assembly source code is very readable because of this and also I think it was unfortunately responsible for the 0-terminated string use because of the ease of writing it that way.
- NobodyNada 3y agoThis is also very common on ARM; they call it a "literal pool": https://developer.arm.com/documentation/dui0473/m/writing-arm-assembly-language/literal-pools https://developer.arm.com/documentation/dui0473/m/writing-ar...
- duskwuff 3y agoThe Thumb encoding for ARM also has some very clever encodings for inline constants: https://developer.arm.com/documentation/ddi0308/d/Thumb-Instructions/Immediate-constants/Encoding https://developer.arm.com/documentation/ddi0308/d/Thumb-Inst... Specifically, it can encode any 8-bit value rotated by any number of bits, as well as any value of the form 0x00XY00XY, 0xXY00XY00, or 0xXYXYXYXY. Combined with the use of inverted instructions (e.g. MVN instead of MOV, SUB instead of AND, BIC instead of AND, etc), this covers a surprising number of the 32-bit constants which are likely to appear in a program.