farhangdon
farhangdon

Reputation: 2003

Writing Assembler Code System Programming

I am working on writing an assembler code. For PASS # 1 I am following all instructions but stuck at the following point Rule when opcode = 'BYTE'

if OPCODE=‘BYTE’ then
            begin
                  find length of constant in bytes
                  add length to LOCCTR
            end {if BYTE}

It says if OPCODE = 'BYTE' then find length of constant and add to Location counter (LOCCTR). I didn't got this step. Can some one clarify it to me please.

I also have this sample input program and its output.

Input Program Below

PROG START 0
FIRST STL RETADDR
SECOND LDA =CꞌABCDꞌ
THIRD LDA =XꞌFFꞌ
J @RETADR
DEF BYTE CꞌDEFꞌ
SYM1 EQU 512

Output of the above program

LINE# LOCCTR  LABEL     OPERATION    OPERAND
01    00000   PROG      START        0
02    00000   FIRST     STL          RETADDR
03    00003   SECOND    LDA          =C’ABCD’
04    00006   THIRD     LDA          =X’FF’
05    00009             J            @RETADR
06    0000C   DEF       BYTE         C’DEF’
07    00200   SYM1      EQU           512
08    0000F   SYM2      EQU           *
09    00003   SYM3      EQU          SECOND-FIRST
10    0000F   RETADDR   RESW         1
11    00012             END          FIRST
12    00012   *         =C’ABCD’
13    00016   *         =X’FF’

Program Length = (12 – 0) + 5 = 17

You can see above when we Reach to Line 6 which contains Byte in the next line the LOCCTR movies to 00200. I am not sure how it happened. Please explain it. Thanks

Upvotes: 0

Views: 233

Answers (1)

ooga
ooga

Reputation: 15501

The EQU instruction is a compile-time instruction that doesn't put anything in memory. It just sets the symbol on the left to the value on the right. If that value is an asterisk (*), then the value is the current value of LOCCTR. Instead of putting the current location in the LOCCTR column, these instructions display the value assigned to them (in hex). So the 00200 is just hex for 512. Similarly, the 0000F for SYM2 is the current location that was assigned to SYM2. And the 00003 beside SYM3 is the value of SECOND-FIRST, which are the addresses of the first and second instructions.

The BYTE instruction is a compile-time instruction that loads data into memory starting at the current location. The rule simply says to add the length of the data to LOCCTR in order to determine where the next part of the program will go.

Notice that line 6, a BYTE instruction, starts at location 0000C and contains the string 'DEF'. That's 3 characters. 0000C + 3 is 0000F, which is the next LOCCTR value after the EQU instructions (which don't put anything in memory).

Upvotes: 1

Related Questions