You are on page 1of 5

Table 1.

Mnemonic/Instructions Addressing mode in use Number of Clock Cycles


CLRA INH (A) 1
STA $03 DIR 3
LDA #$FF IMM 2
STA $01 DIR 3
STA $43 DIR 3
LDA $00 DIR 3
NSA INH 3
STA $40 DIR 3
JMP MainLoop EXT 3

Table 1.2

Event Total number of clock-cycles Elapsed wall-clock time in seconds


IOSetup 12 0.00075
MainLoop 12 0.00075
MainLoop 132 0.00825
10 iterations
Question 2
;*******************************************************************
;* This stationery serves as the framework for a user application. *
;* For a more comprehensive program that demonstrates the more *
;* advanced functionality of this processor, please see the *
;* demonstration applications, located in the examples *
;* subdirectory of the "Freescale CodeWarrior for HC08" program *
;* directory. *
;*******************************************************************

; Include derivative-specific definitions


INCLUDE 'derivative.inc'

; Export Symbols
XDEF _Startup, main
; we export both '_Startup' and 'main' as symbols. Either can
; be referenced in the linker .prm file or from C/C++ later on

XREF __SEG_END_SSTACK ; symbol defined by the linker for the end of the stack

; variable/data section
MY_ZEROPAGE: SECTION SHORT ; Insert here your data definition
; code section
MyCode: SECTION
main:
_Startup:
LDHX #__SEG_END_SSTACK ; stack pointer initialized
TXS
CLI ; interrupts enabled

FirstOperand: EQU $80


SecondOperand: EQU $81
Sum: EQU $84
Difference: EQU $86

mainLoop:
LDA #18 ;loads 18 in A
STA FirstOperand ;stores a into FirstOperand
PSHA ;A pushes on stack
LDA #8 ;load const value 8 in A
PSHA ;push A on stack
STA SecondOperand ;store A in SecondOperand
CLRA ;clears A
STA Sum ;stores in sum
STA Difference ;store A into Difference

JSR sum ;jump to Sum subroutine


PULA ;pull top stack value in A
STA Sum ;store A into Sum
LDA SecondOperand ;load SecondOperand in A
PSHA ;push A on stack

JSR difference ;jump to Difference routine


PULA ;pull value from top stack in A
STA Difference ;store A in Difference

JMP mainLoop

sum:
PSHA ;push A on stack
CLRA ; clear A
LDA 5, SP ;load 5th value from stak on A
ADD 4, SP ;add A with 4th value from stack
STA 4, SP ;store A in 4th position in stack
PULA ;pull from stack on A
RTS ;return to routine called from

difference:

PSHA ;push A on stack

CLRA ;clear A
LDA 5, SP ;load 5th value in A
PSHA ;push
LDA 5, SP ;load value 4th position from stack in A
NEGA ;turn A in 2nd compliment store in A
PSHA ;push A on stack
JSR sum ;return to routine called from
PULA ;pull top value from stack in A
STA 5, SP ;store A onto 5th position in stack
PULA ;pull top value from stack in A
PULA ;pull top value from stack in A
RTS ;return to routine called from

You might also like