7

(avery) #1
FORGE

001c 21 15 18
001d 0d 0a 00 16 19 defb
13,10,0
17 20
Look at line 4:
0000 01 0d 00 4 4 ld bc, hello

We can see that the assembly language instruction
ld bc, hello translates directly to the bytes 0x01,
0x10, and 0x00. 0x01 is the opcode for loading the BC
register pair with the two byes immediately following
the opcode. B is loaded with 0x00, and C is loaded
with 0x10. If we look later in the listing to line 13 and
14, we can see that the label hello corresponds to
address 0x0010.


So, let’s have a closer look at this listing file. There
are five columns, four of which are interesting:


LOC: the memory address of the start of the
line/instruction


OBJECT CODE: the bytes that make up the
assembled instruction, the machine code


LINE: the line in the source file


SOURCE CODE: the code that was in the .asm
source file


Each source instruction is converted into one or
more bytes of machine code. The assembler also
provides some pseudo-instructions such as title,
defm, and defb that are part of the assembler, not the
CPU instruction set.


SIMULATION
Before we go any further, let’s execute the assembled
program, using z80sim as shown in the ‘Running the
code’ box’. We load the bin file with the r command,
giving it the name of the file. We can also provide
the memory address at which to load the machine
code. As we said in the hardware article, the Z80


starts executing at address 0x0000
and z80asm/z80sim assumes that’s
where you want it to start
putting the machine code
it generates/loads.
Once the code
is loaded, we can
execute it with the g
command (short for
go). We can provide the
address to start executing
at, in this case 0000.
We can then see it print
‘Hello, World!’ and stop due to the
halt instruction.
In the simulator we can examine the
contents of memory. We can look at it as
code using the l(ist) command.
There are many more commands available in the
simulator, including debugger features like single
stepping, breakpoints, etc. You can see the list using
the? command.

RUNNING THE CODE


>:z80sim

####### ##### ### ##### ### # #
# # # # # # # # ## ##
# # # # # # # # # # #
# ##### # # ##### ##### # # # #
# # # # # # # # #
# # # # # # # # # #
####### ##### ### ##### ### # #

Release 1.36, Copyright (C) 1987-2017 by Udo Munk

CPU speed is unlimited
>>> r hello.bin,0000
Loader statistics for file hello.bin:
START : 0000
END : 001f
LOADED: 0020

>>> g 0000
Hello, World!
HALT Op-Code reached at 000f

PC A SZHPNC I IFF BC DE HL A’F’ B’C’ D’E’ H’L’ IX IY SP
0010 00 010100 00 00 001f 1f94 38a3 d20b f21c c6c8 adb7 ae55 2b53 1261
>>>

The assembler also provides
some pseudo-instructions
such as title, defm, and defb
that are part of the assembler,
not the CPU instruction set



Below
Originally, code was
loaded into EPROMs
such as this
Free download pdf