The Sample Program

Let us now analyse the sample assembly language program, which is to be found in the main.c file. It is specified one byte at a time, as follows-na:

0: LDI
1: 128
2: 12
3: XCHR
4: 0
5: LDI
6: 0
7: 0xA0
8: LDX
9: XCHR
10: 1
11: LDI
12: 65
13: 131
14: STX
15: 0
16: 0
17: XCHR
18: 0
19: SBI
20: 1
21: 0
22: CMPI
23: 0
24: 0
25: JNA
26: 38
27: 0
28: XCHR
29: 0
30: XCHR
31: 1
32: ADI
33: 2
34: 0
35: JMP
36: 8
37: 0
38: HLT

There are a total of 39 bytes of code, taking up memory locations 0 through 38 in our machine.

Each instruction takes up one byte of memory, and each operand is 8 bits or 16 bits, requiring either one or two bytes of memory.

For each 16 bit operand, the low 8 bits are specified first and the high 8 bits are specified second. This is standard for machines which are known as little endian. Thus, to store the number 15 as a 16 bit number, we first note that the binary for 15 is 0000 0000 0000 1111 (i.e. 8 + 4 + 2 + 1 = 15). Now the lower 8 bits are stored first, followed by the high order 8 bits. So the number is stored as two bytes, 15 then 0. To work out what the value of any 2 byte combination is, multiply the second byte by 256 and add it to the first byte. Thus in our example 0*256 + 15 = 15.