Physics 413 Chapter 4 : Advanced Assembly Programming

Preview:

DESCRIPTION

Physics 413 Chapter 4 : Advanced Assembly Programming. My First Assembly Program. Program adds two 16-bit numbers stored at $1000 - $1001 and $1002 - $1003 and stores the sum at $1010 - $1011 org $2000 ldd $1000 addd $1002 std $1010 end. Assembler Directives and more …. org end equ - PowerPoint PPT Presentation

Citation preview

Physics 413Chapter 4: Advanced Assembly Programming

My First Assembly Program

Program adds two 16-bit numbers stored at $1000 - $1001 and $1002 - $1003 and stores the sum at $1010 - $1011

org $2000

ldd $1000

addd $1002

std $1010

end

Assembler Directives and more …

org

end

equ

db

fcc

Examples

alpha equ 1.7

string fcc “hello!”

array db $3, $8, $23, $11, $57, $12, $47

Delay Loop

DELAY: LDX # $ FFFF

AGAIN : DEX

BNE AGAIN

SWI

Delay Loop Subroutine

here: JSR DELAY

LDAA # $ E3

CMPA $ 50

BNE here

SWI

.

.

.

DELAY: LDX # $ FFFF

AGAIN : DEX

BNE AGAIN

RTS

Stack

Stack is the area of RAM pointed to by the 16-bit Stack Pointer (SP)

LDS functions like LDX

LDS #$ 5C42 The number 5C42 is loaded into SP

LDS $ 5C42 Numbers from 5C43 and 5C42 loaded

LDS $ 5C Numbers from 005D and 005C loaded

Push and Pull

PSHA A MSP SP - 1 SP

PULA SP + 1 SP MSP A

Predict the Outcome!

PSHA

PSHB

PULA

PULB

Solution

Congratulations, if you said the contents of A and B will be swapped and , perhaps more importantly, the value of the stack pointer will be restored to its original value before this program segment was run.

00D6

00D5

00D4

00D3

Detailed Explanation

Suppose that SP was pointing at 00D6 (stack). PUSHA stores A into 00D6. Then PUSHB stores B into 00D5. At this point SP = 00D4. Then PULA pulls 00D5 (which contains B) and stores it into A. Finally, PULB pulls 00D6 (which contains A) and stores it into B. We end up swapping A and B. At this point SP = 00D6, its original value.

00D6

00D5

00D4

00D3

Research Project Ideas Follow . . .

D-Bug12 Built-in Subroutines

Table 4.2 D-Bug12 monitor (version 4.x.x) routines

Subroutine Functionpointer address

far main ( )getchar ( )putchar ( )printf ( )far GetCmdLine ( )far sscanhex ( )isxdigit ( )toupper ( )isalpha ( )strlen ( )strcpy ( )far out2hex ( )far out4hex ( )SetUserVector ( )far WriteEEByte ( )far EraseEE ( )far ReadMem ( )far WriteMem ( )

Start of D-Bug12Get a character from SCI 0 or SCI1Send a character out to SCI 0 or SCI1Formatted string output -translates binary values to stringGet a line of input from the userConvert ASCII hex string to a binary integerCheck if a character (in B) is a hex digitConvert lowercase characters to uppercase Check if a character is alphabeticReturns the length of a NULL -terminated stringCopy a NULL-terminated stringOutput 8-bit number as two ASCII hex charactersOutput a 16-bit number as four ASCII hex charactersSet up a vector to a user 's interrupt service routineWrite a byte to the on -chip EEPROM memoryBulk erase the on -chip EEPROM memoryRead data from the HCS12 memory mapWrite data to the HCS 12 memory map

$EE80$EE84$EE86$EE88$EE8A$EE8E$EE92$EE94$EE96$EE98$EE9A$EE9C$EEA0$EEA4$EEA6$EEAA$EEAE$EEB2

Table 4.2 (Huang)

Table 4.5 Number of pins available in each paralle port

Port Name No. of Pins Pin Name

ABEHJKMPST

PAD1, PAD0LUVW

8888478888

168888

PA7~PA0PB7~PB0PE7~PE0PH7~PH0PJ7~PJ0PK4~PK0PM7~PM0PP7~PP0PS3~PS0PT7~PT0

PAD15~PAD0PL7~PL0PU7~PU0PV7~PV0

PW7~PW0

I/O Ports

Table 4.5 (Huang)

LED Circuit in the Dragon12-Plus Board (Huang)

Figure 4.16 Circuit connection for Example 4.12

PB3

PB2

PB1

PB0

HCS12

PB7

PB6

PB5

PB4

1.5 K

PJ1

74H

C244

PB6PB5PB4PB3PB2PB1PB0

a

bc

defgcommon cathode

a

b

cd

e

fg

HCS12

Figure 4.17 Driving a single seven -segment display

470 each

.

.

.

a

b

g

PB

6

PB

1

PB

0

Figure 4.18 Port B and Port P together drive six seven -segment displays (MC9S12DG256)

. . .

. . .

. . .

74HC244

HCS12

a

b

g

.

.

.

commoncathode

commoncathode

commoncathode

ab

g

.

.

.

800

PP5

PP4

PP0

800

#5#1#0

74HC367

PP3

PP2

PP1

A5

Y0A0

Y5

A4

Y1

A3

A2

A1

Y2

Y3

Y4

VCC

10 K

PA0

PA1PA2PA3

PA4

PA5PA6PA7

HCS12

Figure 4.19 Connecting a set of eight DIP switches to Port A of the HCS 12

SW DIP-8

Look for more research project ideas in the book and on the internet . . .