Chapter. Assembly Language

Chapter 5 Assembly Language Two types of bit patterns • Instructions ‣ Mnemonics for opcodes ‣ Letters for addressing modes • Data ‣ Pseudo-ops, a...
Author: Arleen Lewis
145 downloads 2 Views 580KB Size
Chapter 5

Assembly Language

Two types of bit patterns • Instructions ‣ Mnemonics for opcodes ‣ Letters for addressing modes

• Data ‣ Pseudo-ops, also called dot commands

Figure 5.1

aaa

Addressing Mode

000 001 010 011 100 101 110 111

Immediate Direct Indirect Stack-relative Stack-relative deferred Indexed Stack-indexed Stack-indexed deferred

Letters i d n s sf x sx sxf

Figure 5.2

Instruction Specifier

Mnemonic

Instruction

Addressing Modes

0000 0000 0000 0001 0000 0010 0000 0011

STOP RETTR MOVSPA MOVFLGA

Stop execution Return from trap Move SP to A Move NZVC flags to A

U U U U

0000 010a 0000 011a 0000 100a 0000 101a 0000 110a 0000 111a 0001 000a 0001 001a 0001 010a 0001 011a

BR BRLE BRLT BREQ BRNE BRGE BRGT BRV BRC CALL

Branch unconditional Branch if less than or equal to Branch if less than Branch if equal to Branch if not equal to Branch if greater than or equal to Branch if greater than Branch if V Branch if C Call subroutine

i, x i, x i, x i, x i, x i, x i, x i, x i, x i, x

0001 100r 0001 101r 0001 110r 0001 111r 0010 000r 0010 001r

NOTr NEGr ASLr ASRr ROLr RORr

Bitwise invert r Negate r Arithmetic shift left r Arithmetic shift right r Rotate left r Rotate right r

U U U U U U

Status Bits

NZ NZV NZVC NZC C C

0000 100a 0000 101a 0000 110a 0000 111a 0001 000a 0001 001a 0001 010a 0001 011a

BRLT BREQ BRNE BRGE BRGT BRV BRC CALL

Branch if less than Branch if equal to Branch if not equal to Branch if greater than or equal to Branch if greater than Branch if V Branch if C Call subroutine

i, x i, x i, x i, x i, x i, x i, x i, x

0001 100r 0001 101r 0001 110r 0001 111r 0010 000r 0010 001r

NOTr NEGr ASLr ASRr ROLr RORr

Bitwise invert r Negate r Arithmetic shift left r Arithmetic shift right r Rotate left r Rotate right r

U U U U U U

0010 01nn 0010 1aaa

NOPn NOP

Unary no operation trap Nonunary no operation trap

U i

0011 0aaa 0011 1aaa 0100 0aaa 0100 1aaa 0101 0aaa

DECI DECO STRO CHARI CHARO

Decimal input trap Decimal output trap String output trap Character input Character output

d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf d, n, sf d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf

0101 1nnn

RETn

Return from call with n local bytes

U

0110 0aaa 0110 1aaa

ADDSP SUBSP

Add to stack pointer (SP) Subtract from stack pointer (SP)

i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf

NZVC NZVC

0111 raaa 1000 raaa 1001 raaa 1010 raaa 1011 raaa

ADDr SUBr ANDr ORr CPr

Add to r Subtract from r Bitwise AND to r Bitwise OR to r Compare r

i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf

NZVC NZVC NZ NZ NZVC

Figure 5.2 (Continued)

NZ NZV NZVC NZC C C

NZV

0010 01nn 0010 1aaa

NOPn NOP

Unary no operation trap Nonunary no operation trap

U i

0011 0aaa 0011 1aaa 0100 0aaa 0100 1aaa 0101 0aaa

DECI DECO STRO CHARI CHARO

Decimal input trap Decimal output trap String output trap Character input Character output

Figure 5.2NZV d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx,(Continued) sxf d, n, sf d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf

0101 1nnn

RETn

Return from call with n local bytes

U

0110 0aaa 0110 1aaa

ADDSP SUBSP

Add to stack pointer (SP) Subtract from stack pointer (SP)

i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf

NZVC NZVC

0111 raaa 1000 raaa 1001 raaa 1010 raaa 1011 raaa

ADDr SUBr ANDr ORr CPr

Add to r Subtract from r Bitwise AND to r Bitwise OR to r Compare r

i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf

NZVC NZVC NZ NZ NZVC

1100 raaa 1101 raaa 1110 raaa 1111 raaa

LDr LDBYTEr STr STBYTEr

Load r from memory Load byte from memory Store r to memory Store byte r to memory

i, d, n, s, sf, x, sx, sxf i, d, n, s, sf, x, sx, sxf d, n, s, sf, x, sx, sxf d, n, s, sf, x, sx, sxf

NZ NZ

The unimplemented opcode instructions • NOPn • NOP • DECI • DECO • STRO

Unary no operation trap Nonunary no operation trap Decimal input trap Decimal output trap String output trap

Pseudo-operations • .ADDRSS • .ASCII • .BLOCK • .BURN • .BYTE • .END • .EQUATE • .WORD

The address of a symbol A string of ASCII bytes A block of bytes Initiate ROM burn A byte value The sentinel for the assembler Equate a symbol to a constant value A word value (two bytes)

Figure 5.3

Assembler Input ;Stan Warford ;January 13, 2009 ;A program to output "Hi" ; CHARO 0x0007,d ;Output 'H' CHARO 0x0008,d ;Output 'i' STOP .ASCII "Hi" .END

Assembler Output 51 00 07 51 00 08 00 48 69 zz

Program Output Hi

Figure 5.4

7

Application level

6

High-order language level

5

Assembly level

4

Operating system level

3

Instruction set architecture level

2

Microcode level

1

Logic gate level

Figure 5.5

Input CHARO CHARO STOP .ASCII .END

0x0007,d 0x0008,d "Hi"

Processing

Output

Assembler

51 00 07 51 00 08 00 48 69 zz

Figure 5.6

Assembler Input CHARI CHARI CHARO CHARO STOP .BLOCK .BLOCK .END

0x000D,d 0x000E,d 0x000E,d 0x000D,d

;Input first character ;Input second character ;Output second character ;Output first character

1 1

;Storage for first char ;Storage for second char

Assembler Output 49 00 0D 49 00 0E 51 00 0E 51 00 0D 00 00 00 zz

Program Input up

Program Output pu

Figure 5.7

Assembler Input LDA ADDA ORA STBYTEA CHARO STOP .BLOCK .WORD .WORD .WORD .END

0x0011,d 0x0013,d 0x0015,d 0x0010,d 0x0010,d

;A