views:

54

answers:

2

I am making an emulator for Z80 binaries but I cannot find out whether all the integer data types are signed or unsigned from the manual or from google. So are the numbers from registers A,B...HL,BC etc signed or not?

Also, in machine code are the bytes/words/addresses which come after the instructions as arguments signed or unsigned?

Like in these examples (from 8080/Z80 Instruction Set):

8080 Mnemonic    Z80 Mnemonic    Machine Code    Operation
-------------    ------------    ------------    ---------
MVI A,byte       LD  A,byte      3Ebyte          A <- byte
LXI B,word       LD  BC,word     01word          BC <- word
JMP address      JP  address     C3address       PC <- address

Thanks in advance.

+2  A: 

AKAIK, Assembly language data and transfer instructions don't contain sign information. Both data and transfer operations define only data size. Sign information is part of some instructions, like signed/unsigned multiplication instructions. So, the same register may be handled by imul instruction as signed integer, and by mul instruction as unsigned integer.

Alex Farber
I see, so an `add` instruction will perform addition on both a signed and unsigned integer. This is annoying to say the least because my emulator is being written in C# and doesn't support just adding the raw data. I'll do some ASM interop thing.
Callum Rogers
Are you sure about this? I'm more interested in the machine code than the assembly. Are addresses always formatted as unsigned then, because it would seem ridiculous to have negative addresses?
Callum Rogers
Assembly is just human-readable translation of machine code. Every Assembly instruction exactly matches some opcode, and and vice versa. Regarding addresses, the point is what instructions are working with them, and how they are interpreted. Of course, address is always treated as positive number. But offset may be negative.
Alex Farber
Not true, assembly is not necessarily 1:1 to machine code.
Jens Björnhager
+1  A: 
  1. The registers can contain either, and most operands calculate both answers at the same time because of Two's complement. Some instructions do however need information whether the containing value is signed or unsigned. They exist in two forms, one for signed and one for unsigned. Can't remember whether Z80 has any of these.

  2. See (1.) Absolute addresses are unsigned and relative addresses (branches) are signed, to be able to jump backwards.

Jens Björnhager