Question 8.1: Suppose that we want a program starting in memory location 0...
Suppose that we want a program starting in memory location 0400 that retrieves the number stored in location 0500, adds 5 to the number, writes the result to location 0500, and then stops. (We will use only the instructions listed in Table 8.1, even though the CPU12 has many additional instructions, which often could make our programs shorter.)
Learn more on how we answer questions.
Comments have been included to explain the purpose of each line. BEGIN is a label that identifies the address of the LDAA instruction. (In this case, BEGIN has a value of 0400.) If we wanted to reference this location somewhere in a more complex program, the label would be useful. STOP is the mnemonic for the instruction that halts further action by the MCU. END is a directive that informs the assembler that there are no further instructions.
The source code is: ; SOURCE CODE FOR EXAMPLE 8.1 ; THIS LINE IS A COMMENT THAT IS IGNORED BY THE ASSEMBLER ; ORG $0400 ;ORIGIN DIRECTIVE BEGIN LDAA $0500 ;LOAD NUMBER INTO A ADDA #$05 ;ADD 5, IMMEDIATE ADDRESSING STAA $0500 ;STORE RESULT STOP END ;END DIRECTIVE |