Here you will find a very simple program (fragment) that compares two numbers and
jumps to a particular label, whichever is larger. The two numbers are stored in the
memory at the symbolic addresses VALUE_X and VALUE_Y. This example assumes that the
numbers in the unsigned representation are interpreted.
Copy the program to the MC8ASM and have it assembled.
Then copy the Intel Hex code into the MC8 simulator and run it.
The example is not about the (not necessarily present) meaningfulness or efficiency
of the code, but how the individual instructions are executed and what happens in
the registers and on the buses of the MC8.
You can also compare other values ??(for this, you have to change the two values ??
for WERT_X and VAL_Y in the MC8ASM) and observe how the flags are set according to
the result.
The result of the comparison is inter alia. To recognize which of the HALT commands
the MC8 is executing. Is the PC after that
14h, the HALT command was executed at "Y_GL_X"
15h, the HALT command was executed at "Y_KL_X"
16h, the HALT command was executed at "Y_GR_X".
In addition to the material in the exercises, it is also relevant for the exam to
familiarize you with all the commands used in this code!
Special task: Rewrite the program so that the comparison works for numbers in the
two's complement representation.
Beispielprogramm B
;BESPIELPROGRAMM
;DIGITALE SYSTEME UE 384.047
;2. Labor "MC8" - Fernlehre
;Read in first value of memory location WERT_X
MOV A,WERT_X
MOV B,A ;A free
;Read second value of memory location WERT_Y
MOV A,WERT_Y
;Comparison
CP B ;A-B
; This command is used to enter the A register
, Not modified, but the flags are set!
JPZ Y_GL_X ;When the zero flag is set,
;Then the two values were the same
;-> jump to "Y equals X"
JPC Y_KL_X ;When the carry flag is set,
;Then because register A < register B,
;(also value Y <value X)
;-> jump to "Y smaller X"
JP Y_GR_X ;Y is therefore not EQUAL X
;and also not SMALLER X
;So GREATER X
;-> jump to "Y greater X"
WERT_X: DB 04h ;1. Comparison value
WERT_Y: DB 40h ;2. Comparison value
Y_GL_X: ;blah, ;here is the code, the
;blah ;is to be executed,
;blah ;if Y = X
;blah ;(any commands)
HALT
Y_KL_X: ;blah ;here is the code, the
, Blah, ;is to be executed,
; Blah, ;if Y <X
; Blah; ;(any commands)
HALT
Y_GR_X: ;blah ;here is the code, the
, Blah, ;is to be carried out,
; Blah, ;if Y> X
; Blah; ;(any commands)
HALT
MC8ASM.select the menu item Own program in the configuration ROM and enter the
machine code of the program to be simulated in IntelHex format.
:030000003A1100B2
:0100030047B5
:030004003A1200AD
:01000700B840
:03000800CA130018
:03000B00DA140004
:03000E00C3150017
:0100110004EA
:0100120040AD
:010013007676
:010014007675
:010015007674
:00000001FF
MC8ASM.select the menu item Own program in the configuration ROM and enter the
machine code of the program to be simulated in IntelHex format.