Machine Language Programming
Objective
To compute the sum FFFD + 0024 + 0100.
Approach
Place the data, that is the values to be added, in memory at some address.
Write a program that starts by reading the first value, and loops three times,
accumulating the values read each time. When the program emerges from the
loop, the sum of the values has been computed.
Steps
Place data in memory
We will place the three numbers in memory starting at the arbitrarily
selected location 20050.
Place program in memory
If we placed the starting address of the data in register BX and the
ending address in register DX, the following assembly program would the
sum the numbers and leave the result in register AX. The numbers on
the left are offsets (addresses) of the instructions.
- 0000
- - SUB AX,AX; subtract AX from itself to make it 0
- 0002
- - ADD AX, [BX]; add word pointed to by BX to AX
- 0004
- - ADD BX,2; Add 2 to BX to make it point to the next 16-bit
word
- 0007
- - CMP DX,BX; compare DX and BX
- 0009
- - JGE L1; if DX >= BX, then jump to instruction
0002
Since we do not have the services of an assembler, we will place the machine
instructions (in hexadecimal) in memory. The hexadecimal representation
of the program above is:
- 0000
- - 2BC0
- 0002
- - 0307
- 0004
- - 83C302
- 0007
- - 3BD3
- 0009
- - 79F7
There is a one-to-one correspondence between the machine instructions and
the assembly instructions.
The DEBUG utility
We will use the DEBUG utility
to place program and data in memory as shown
here
.
File translated from
TEX by
TTH
, version 3.01.
On 15 Mar 2002, 10:22.