Reputation: 97
Why the mechanism used for calculating the address of a subroutine called by ACALL
(from the instruction set of intel 8051 controller) is so complex. Why don't they put the address of the instruction directly and jump to that address like we do in LCALL instruction.
Regards
Upvotes: 0
Views: 285
Reputation: 58812
LCALL
being a 3 byte instruction you get an opcode and 16 bit of absolute address. ACALL
exists as a shorter version that fits into 2 bytes. The simple approach would have been to just use 8 bits for address, but the engineers decided to allow 11 bits for greater range, with the top 3 bits encoded in the opcode itself. 8 bits would have been probably too constraining even considering the typically small size of 8051 programs.
Arguably the encoding scheme isn't terribly complex (in microcontrollers few things are), you just have to put the address together from 3 parts:
pc
= [top 5 bits of current program counter] [3 bits from the opcode] [8 bits from the operand]
Long story short: if your function is within range of an ACALL
, you can spare a byte. Your assembler may be able to choose between ACALL
and LCALL
automatically.
Upvotes: 3