Assembly Program: Illustration of Directives, Instructions, and Memory Organization - Prof, Study notes of Electrical and Electronics Engineering

An assembly program illustration, explaining the use of labels, directives, mnemonics, operands, and memory organization. The program copies data from one record to another, counting the number of bytes in each record. It also differentiates between program and data memory, and instruction, directives, and opcodes.

Typology: Study notes

Pre 2010

Uploaded on 07/28/2009

koofers-user-niv
koofers-user-niv 🇺🇸

5

(1)

9 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Program Assembly Illustration
ASSEMBLY OF DIRECTIVES AND ASM INSTRUCTIONS
Assembly Code Assembled Code (.LST file)
label1 mnemonic2 operand3 prog./data machine opcode5
directive1 mem. addr.4
ORG $6000 =00006000
D_REC FCB $AA,$BB,$CC,$FF,$EE,$01 6000 AA BB CC FF EE 01
FCB $A1,$B2,$C3,$F4,$01 6006 A1 B2 C3 F4 01
FCB $81,$72,$63,$54,$45,$E5,$01 600B 81 72 63 54 45 E5 01
RESULT RMB $0A 6012 +000A
D_CPY RMB $10 601C +0010
ORG $4000 =00004000
LDS #$8000 4000 CF 8000
LDX #D_REC 4003 CE 6000
LDY #D_CPY 4006 CD 601C
LDAA #$0 4009 86 00
PSHA 400B 36
LOOP LDAB 0,X 400C E6 00
STAB 0,Y 400E 6B 40
CMPB #$01 4010 C1 01
BEQ ENDLP 4012 27 05
INX 4014 08
INY 4015 02
INCA 4016 42
BRA LOOP 4017 20 F3
ENDLP PULB 4019 33
PSHY 401A 35
LDY #RESULT 401B CD 6012
STAA B,Y 401E 6A ED
PULY 4020 31
INCB 4021 52
PSHB 4022 37
CPX #RESULT 4023 8E 6012
BEQ DONE 4026 27 05
INX 4028 08
INY 4029 02
CLRA 402A 87
BRA LOOP 402B 20 DF
DONE TBA 402D 18 0F
END
Notes:
1. Labels and Directives are used by the assembler to simplify writing code and direct the assembly
process. During assembly, all labels are replaced with appropriate hexadecimal values. Directives do
not result in any program opcodes, although they can generate data to be stored in memory.
2. Mnemonics are shorthand names for assembly instructions. Mnemonics will be converted to
hexadecimal opcodes (machine code) during the assembly process that are loaded into
microcontroller program memory to form the program that can be executed.
3. Operands are the data parameters needed to complete a program instruction or assembly directive
statement. Hexadecimal operands must be begin with a ‘$’ so the assembler knows the value is not a
decimal. The address mode for instructions is determined by the format of the operand; e.g., ‘#’
specifies an immediate instruction where the operand is the parameter value not an address
containing the parameter value. Multiple operands can be separated by comma or tabs, depending
on the assembler used to assemble the code.
pf3

Partial preview of the text

Download Assembly Program: Illustration of Directives, Instructions, and Memory Organization - Prof and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Program Assembly Illustration

ASSEMBLY OF DIRECTIVES AND ASM INSTRUCTIONS

Assembly Code Assembled Code (.LST file)

label 1 mnemonic^2 operand 3 prog./data machine opcode^5 directive 1 mem. addr. 4 ORG $6000 = D_REC FCB $AA,$BB,$CC,$FF,$EE,$01 6000 AA BB CC FF EE 01 FCB $A1,$B2,$C3,$F4,$01 6006 A1 B2 C3 F4 01 FCB $81,$72,$63,$54,$45,$E5,$01 600B 81 72 63 54 45 E5 01 RESULT RMB $0A 6012 +000A D_CPY RMB $10 601C + ORG $4000 = LDS #$8000 4000 CF 8000 LDX #D_REC 4003 CE 6000 LDY #D_CPY 4006 CD 601C LDAA #$0 4009 86 00 PSHA 400B 36 LOOP LDAB 0,X 400C E6 00 STAB 0,Y 400E 6B 40 CMPB #$01 4010 C1 01 BEQ ENDLP 4012 27 05 INX 4014 08 INY 4015 02 INCA 4016 42 BRA LOOP 4017 20 F ENDLP PULB 4019 33 PSHY 401A 35 LDY #RESULT 401B CD 6012 STAA B,Y 401E 6A ED PULY 4020 31 INCB 4021 52 PSHB 4022 37 CPX #RESULT 4023 8E 6012 BEQ DONE 4026 27 05 INX 4028 08 INY 4029 02 CLRA 402A 87 BRA LOOP 402B 20 DF DONE TBA 402D 18 0F END

Notes:

  1. Labels and Directives are used by the assembler to simplify writing code and direct the assembly process. During assembly, all labels are replaced with appropriate hexadecimal values. Directives do not result in any program opcodes, although they can generate data to be stored in memory.
  2. Mnemonics are shorthand names for assembly instructions. Mnemonics will be converted to hexadecimal opcodes (machine code) during the assembly process that are loaded into microcontroller program memory to form the program that can be executed.
  3. Operands are the data parameters needed to complete a program instruction or assembly directive statement. Hexadecimal operands must be begin with a ‘$’ so the assembler knows the value is not a decimal. The address mode for instructions is determined by the format of the operand; e.g., ‘#’ specifies an immediate instruction where the operand is the parameter value not an address containing the parameter value. Multiple operands can be separated by comma or tabs, depending on the assembler used to assemble the code.
  1. Once ASM code is assembled, all instructions and data are assigned to memory addresses. The addresses are determined by ORG directives in the ASM code. It is useful to differentiate between program memory, where instructions (and their operands) are stored and data memory, where non- instruction data fields are stored. Program memory contains the opcodes that will be fetched and decoded during program execution. Data memory contains data values read during program execution or results stored during program execution.
  2. Operation codes, or opcodes, are hexadecimal values representing instructions and their operands. Opcodes are also referred to as machine code because the binary equivalents of these codes tell the microcontroller exactly what do to. For assembly instructions, the first byte of each line of opcode translates to a specific instruction mnemonic while the remaining values are instruction parameters (operands). Assembly instruction opcode values will be stored in microcontroller program memory, at the address indicated beside each line of opcode, and executed when the program is run. For data directives, data values are stored directly to data memory at the address specified before the data values. These values are not instructions and can not be executed as program opcodes.

Machine Code Upload Record (.S19 file)

S0030000FC

S1136000AABBCCFFEE01A1B2C3F

S1136010E

S10F

S1134000CF8000CE6000CD601C860036E6006B

S1134010C101270508024220F33335CD60126AED

S11240203152378E6012270508028720DF180FF

S9030000FC

Notes:

YELLOW HIGHLIGHTS show memory addresses GREEN HIGHLIGHTS show data for data memory PINK HIGHLIGHTS show reserved memory bytes in data memory, initiated with value 00 BLUE HIGHLIGHTS show ASM program opcodes to be stored in program memory

MEMORY SPACE

MEMORY

MCU Registers

Program

Data

Stack

Unused/ Reserved

Unused/ Reserved

ADDRESS

$

$

$

$

4000 CF 4001 80 4002 00

402D 18 402E 0F

. . .

6000 AA 6001 BB

602B 00 602C 00

. . .

7FFF

} one instruction

top of program

top of data

end of data

bottom of stack

top of stack (varies)

end of program

more data /sta ck

more progra m