5

I'm debugging an old PC BIOS and it has most of its constant strings interspersed directly with the code, like this:

enter image description here

As the comment notes, the function putsc will take the string as its argument, finding it via the return address! After iterating over the string, it actually patches the stack to make a proper return.

enter image description here

My question, and I hope it's not too vague:

Is or was passing constant arguments like this, sticking them right after the call, in any way a common technique for low-level (hand-written?) code such as this?

Why would you even prefer to do it this way rather than using a table of strings elsewhere?

  • Out of curiosity, which PC BIOS specifically? Additionally, depending on how old the BIOS is, there is a StackExchange site focused on retrocomputing you could check out – julian Aug 5 '18 at 12:40
  • It is BIOS version 3F for a Toshiba T3200SX by Phoenix, which identifies itself as "T3200SX V3.30" and also contains the string "80386 ROM BIOS PLUS Version 1.10 07". Thanks for the pointer! – pesco Aug 5 '18 at 14:03
4

This technique allows the code to be position-independent, since there are no explicit references to the specific address that holds the string. Instead, the call instruction will push onto the stack whatever address was current at the time. Depending on the assembler (if any) that was used to produce the code, this might simplify some things. If the code was entirely hand-crafted by typing in hex values, then having position-independence allows other instructions to be inserted without having to recalculate addresses.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.