Download 3.4.1 MOVE(CONT.)

Document related concepts
no text concepts found
Transcript
 Message sent by programmers (program
instructions) understood by the computer
and vice versa.
 Language that friendly to human also
understandable to computer systems.
 Three level of language:
 Low level – machine language
 Middle level – assembly language
 High level – high-level language
 Machine language:




Natural language of a particular computer system.
Strings of numbers or binary codes (0 or 1).
Machine-dependant (differ from one µP to other µP.
Programmers need to know specifically the
architecture of CPU.
 Assembly language:
 Using english-like abbreviations (MUL).
 Overcome problems – writing machine language is
too slow and tedious.
 Assembler as translator.
 Programmer need to know the basic architecture.
 High-level language:
 Using everyday English and common mathematical




notation. (x = I + j)
Overcome problems : assembly language require
many instruction to accomplish a simple task.
Single instruction in HLL = several AL instructions.
Compiler as translator.
Programmers do not need to know the architecture of
CPU.
 There are many MC68000 instructions. However,
theses instructions comply to a standard instruction
format:
 Label – a user-defined symbol representing the address
associated with the instruction. Up to 8 alphanumeric,
begin with letter, terminated by a space.
SLIDE 48
 Operator .
 a mnemonic code for MC68000 instructions .
 An assembler directive / pseudo-instruction / pseudo-
operation.
 Macro call (repetitive instructions in a program which are
codified only once and can be used as many times as
necessary)
 Operand – depends on the operator, may has more
than one operand.
 Comment – explanation about the execution of
instruction.
 Data format:
 Byte | Word | Longword | Sign-extended
 Transfer / move data between registers and memory.
 Instructions of data transfer group.
MOVE.B D1,D2
MOVE.B D6,CCR
MOVE.W SR,D6
MOVE.L USP,A1
MOVE.L A2,USP
MOVEA.W #$4321,A0
MOVEQ.B #01,D4
MOVEM.W D2/D4-D6, $4000
MOVEM.L $4000,D0-D5
LEA
START,A0
EXG
SWAP
CLR.B
D1,D2
D3
$3000
 Byte(B), Word(W) and Long word(L).
 R R , R M , M M , EA SR , USP An
 Example 1:
 MOVE.W #$72,D1
 Before : D1 = $00200500
 After : D1 = $00200072
# menunjukkan data
sebenar.
$ menunjukkan nombor
heksa
 Example 2:
 MOVE.B D0,D1
 Before : D1 = $00200500 , D0 = $00002222
 After : D1 = $00200522 , D0 = $00002222
 Example 3:
 MOVE.B $3000,D1
 Before : D1 = $00200500 ,
 After : D1 = $00200532 ,
$3000
32
$3001
43
$3002
98
 Example 4:
$4000
3254
$4000
32
 MOVE.W D6,$4000
$4002
4377
@ $4001
54
 Before: D6 = $AB206541 ,
$4004
9868
$4002
43
 After : D6 = $AB206541 ,
 Example 5:
$4000
6541
$4002
4377
$4004
9868
@
$4000
65
$4001
41
$4002
43
 MOVEA.W D6,A2
 Before : D6 = $AB206541 , A2 = $ABCD1234
 After : D6 = $AB206541 , A2 = $00006541
 Example 6:
 MOVEA.W D6,A2
 Before : D6 = $AB20A541 , A2 = $ABCD1234
 After : D6 = $AB206541 , A2 = $FFFFA541
 Example 7:
 MOVEA.L D6,A2
 Before : D6 = $AB206541 , A2 = $ABCD1234
 After : D6 = $AB206541 , A2 = $AB206541
 Example 8:
-128 (80) hingga 127 (7F)
 MOVEQ #$04,D3 (MOVEQ #XXX,Dn)
 Before : D3 = $AB206541
 After : D3 = $00000004
 Example 9:
 MOVEQ #$80,D3
 Before : D3 = $AB206541
 After : D3 = $FFFFFF80
 Example 10:
 MOVEM.W D2/D5/D0,$200
$200 6541
 Before : D0 = $11112222 ,
D2 = $33334444 , $202 4377
D5 = $55556666 , $204 9868
 After : D0 = $11112222 , $200 4444
D2 = $33334444 , $202 6666
D5 = $55556666 , $204 2222
 Example 11:
Predecrement (tolak dulu)
B:–1,W:–2,L:–4
Dlm contoh ada 3 daftar
maka 3x4=12 ,
50C – C = 500
 MOVEM.L D2/D5/D0,-(A4)
 Before : D0 = $11112222 , D2 = $33334444 ,
$500
451287A4
$504
54A2F221
D5 = $55556666 , A4 = $0000050C
 After : D0 = $11112222 ,
$500 33334444
D2 = $33334444 ,
$504 55556666
D5 = $55556666 ,
$508 11112222
A4 = $00000500
$508 846AC1DD
$50C
45123211
 Example 12:
 MOVEM.W $200,D2/D5/D0
$200 6541
 Before : D0 = $11112222 ,
D2 = $33334444 , $202 4377
D5 = $55556666 , $204 9868
 After : D0 = $FFFF9868 , $200 6541
D2 = $00006541 , $202 4377
D5 = $00004377 , $204 9868
 Example 13:
Posincrement (tmbh kmdn)
B:+1,W:+2,L:+4
Dlm contoh ada 3 daftar
maka 3x4=12 ,
500 + C = 50C
 MOVEM.L (A4)+,D2/D5/D0
 Before : D0 = $1111222 , D2 = $33334444 ,
$500
451287A4
$504
54A2F221
D5 = $55556666 , A4 = $00000500
 After : D0 = $846AC1DD ,
$500 451287A4
D2 = $451287A4 ,
$504 54A2F221
D5 = $54A2F221 ,
$508 846AC1DD
A4 = $0000050C
$508 846AC1DD
$50C
45123211
 Example 14:
 MOVEP.W D2,1(A1)
 Before : D2 = $AB206541 ,
$501
FF
$502
FF
A1 = $00000501
 After : D2 = $AB206541 ,
A1 = $00000501
$503
FF
 Example 15:
$501
FF
$502
65
$503
41
$502 dan
$501 adalah
alamat I/O
 EXG D1,D5
 Before : D1 = $11223344 , D5 = $66778899
 After : D1 = $66778899 , D5 = $11223344
 Example 16:
 SWAP D1
 Before : D1 = $11223344
 After : D1 = $33441122
 Example 17:
OPER
EQU
$2001
MOVEA.L #OPER,A1

OPER

MOVEA.L #$2001,A1
EQU
LEA
$2001
OPER,A1


LEA
$2001,A1
 After : A1 = $00002001
 MOVEA.L $2001,A1 ≠ LEA $2001,A1
 Example 18:
 CLR.B D1
 Before : D1 = $11223344
 After : D1 = $ 11223300
ADD.W
ADD.L
ADDI.B
ADDQ.W
ADDX
ADDX
ADDA
SUB.W
SUB.L
SUBI.B
SUBQ.W
SUBX
SUBX
SUBA
NEG
NEGX
MULS
MULU
DIVS
DIVU
EXT.W
EXT.L
$300,D1
D2,$218
#$44,D3
#$32,D2
D1,D2
-(A1),-(A3)
$100,A6
$300,D1
D2,$218
#$44,D3
#$32,D2
D1,D2
-(A1),-(A3)
$100,A6
D1
A4
$32,D5
#$04,D5
$32,D5
#$04,D5
D3
D2
 Byte(B), Word(W) and Long word(L).
 Data via register, memory, absolute data and I/O port.
 Example 1:
 ADDI.W #$72,D1
 Before : D1 = $00200500
 After : D1 = $00200572
 Example 2:
 ADD.L D0,D1
 Before : D1 = $00200500 , D0 = $00002222
 After : D1 = $00202722 , D0 = $00002222
 Example 3:
 ADD.W $3000,D1
 Before : D1 = $00200500 ,
 After : D1 = $00203743 ,
$3000
32
$3001
43
$3002
98
 Example 4:
$4000
3254
$4000
32
 ADD.W D6,$4000
$4002
4377
@ $4001
54
 Before: D6 = $AB206541 ,
$4004
9868
$4002
43
 After : D6 = $AB206541 ,
 Example 5:
$4000
9795
$4002
4377
$4004
9868
@
$4000
97
$4001
95
$4002
43
 ADDA.W D6,A2
 Before : D6 = $AB206541 , A2 = $ABCD1234
 After : D6 = $AB206541 , A2 = $ABCD7775
 Example 6:
 ADDA.L D6,A2
 Before : D6 = $AB20A541 , A2 = $ABCD1234
 After : D6 = $AB206541 , A2 = $56EDB775 , C = 1
 Example 7:
 ADDX.B D2,D3
 Before : D2 = $AB206541 , D3 = $ABCD1234 , X = 1
 After : D2 = $AB206541 , D3 = $AB206576 , X = 1
 Example 8:
-128 (80) hingga 127 (7F)
 ADDQ.B #$04,D3 (ADDQ #XXX,Dn)
 Before : D3 = $AB206541
 After : D3 = $AB206545
 Example 9:
 SUB.W #$80,D3
 Before : D3 = $AB206541
 After : D3 = $AB2064C1
 Example 10:
@ menunjukkan nombor
octal
% menunjukkan nombor
binari
 SUBI.L #10,D2
 Before : D2 = $AB206541
 After : D2 = $AB206537
 Example 11:
 SUBQ.W #@11,D3 (SUBQ #XXX,Dn)
 Before : D3 = $AB206541
-128 (80) hingga 127 (7F)
 After : D3 = $AB200038
 Example 12:
 NEG.W D3
NEG = Pelengkap 2
 Before : D3 = $AB206541
$41
=
Songsangkan
 After : D3 = $AB209ABF
$BF
=
01000001
10111110
+
1
10111111
 Example 13:
 MULU #2,D2 ;16 bit x 16 bit = 32 bit
 Before : D2 = $AB206541
 After : D2 = $0000CA82
 Example 11:
 MULU #2,D2
@ menunjukkan nombor
octal
% menunjukkan nombor
binari
 Before : D2 = $AB20FFFF
 After : D2 = $0001FFFE
 Example 12:
 DIVU #2,D3
;32 bit / 16 bit = 16 bit lower (result)
16 bit upper ( remainder)
 Before : D3 = $00006541
6541F = 25921
 After : D3 = $000132A0
32A016 = 1296010
AND.W
AND.L
ANDI.B
ANDI
ADDI
$300,D1
D2,$218
#$44,D3
#%11011,CCR
#$25,SR
OR.W
OR.L
ORI.B
ORI
ORI
$300,D1
D2,$218
#$44,D3
#%11011,CCR
#$25,SR
EOR.W
EORI.B
EORI
EORI
$300,D1
#$44,D3
#%11011,CCR
#$25,SR
NOT.W
D2
 Example 1:
 AND.B #$3E,D1
 Before : D1 = $12345674
 After : D1 = $12345634
 Example 2:
 OR.B D0,D1
 Before : D1 = $1234563E , D0 = $98765474
 After : D1 = $1234567E , D0 = $98765474
 Example 3:
 NOT.B D1
 Before : D1 = $12345655 ,
 After : D1 = $123456AA ,
 Example 4:
B : 0 to 255 | $00 - $FF
 Example 5:
B : 0 to 255 | $00 - $FF
 Example 6:
B : 0 to 255 | $00 to $FF
 Example 7:
B : 0 to 255 | $00 to $FF
 Example 8:
B : 0 to 127 | $00 - $7F
-1 to -128 | $FF to $8F
 Example 9:
B : 0 to 127 | $00 - $7F
-1 to -128 | $FF to $8F
 Example 10:
 Normally : PC point to the next instruction.





PC has the address of next instruction.
Jump / branch : PC will be load with target address.
Jump : unconditional
Branch : conditional
Example:
JMP $8450
BCS $8A50
PC is a 32 bit register.
 Conditional transfer instruction
i. Bcc instruction (Branch conditionally)
Format: Bcc DST
Example:
START MOVE.W D3,D4
…..
BNE
NEXT
;(Branch if Z=0)
NEG
D3
….
NEXT SUB.W
#32, D1
ii. DBcc instruction (test condition, decrement & branch)
Format: DBcc Dn,DST
Operation:
Test condition;
i. condition met; no branch, execute next instruction.
ii. condition not met; (Dn - 1)
if Dn ≠ -1; branch to DST
if Dn = -1; no branch, execute next instruction.
Example:
START CLR.L
D4
; D4 = $00000000
…..
DBNE
D4,NEXT
; condition (Z=0)
NEG
D3
….
NEXT SUB.W#32, D1
iii. Scc instruction (set conditionally)
Format: Scc DST
Operation:
Test condition:
i. condition met; DST will get 1s
ii. condition not met; DST will get 0s
No branch involved.
Example:
START
CLR.L
D4 ; Z = 1
SNE
D5 ; D5 = $00000000
 JMP
 – always jump to any address.
 JMP DST
 BRA




always branch but up to 65536 (216) address.
BRA DST
.S for branch to 256 (28) address
BRA.S DST
 NOP
 no operation
 delay in execution time.
 STOP
 operand loads into status register and stop.
 STOP #$78
 Stack is a data structure that can be used to save data.
 Stack works in LIFO concept.
 There are two (2) stack:
User Stack – point by USP & Supervisor Stack – point by SSP
 PUSH data into stack.
 1. decrement SP
2. move data into stack
 MOVE.B D1,-(A0)
 POP data from stack.
 1. move data from stack
2. increment SP
 MOVE.B (A0)+,D1
 An approach to simplify a long and complex program.
 Grouping repeated instructions into subroutine.
 This subroutine will be called when needed.
 Operation:
 Before executing subroutine,
current data (registers, SR, PC)
need to be save in stack first.
 Subroutine is carried out
 After the subroutine finish,
data in stack will be restored
back.
 Instruction : JSR, BSR, RTS, RTR
 JSR
 JSR EA – the subroutine maybe anywhere in the
memory.
 Operation:
 PC  -(SP)
 EA  PC
 BSR
 BSR EA – the subroutine must be within 65536
address
 Operation:
 PC  -(SP)
 PC + d  PC
 RTS
 RTS – return from subroutine
 Operation:
 (SP)+  PC
 RTR
 RTR – return and restore CCR
 Operation:
 (SP)+  CCR
 (SP)+  PC
68000 INSTRUCTIONS:
 DATA TRANSFER/ MOVE GROUP
 move,movem,lea,exg,swap,clr
 ARITHMETIC OPERATION
 add,sub,neg,mul,div,ext
 LOGICAL OPERATION
 and,or,not,eor
 SHIFT AND ROTATE (x)
 lsl,lsr,asl,asr,rol,ror,roxl,roxr (x)
 CONTROL TRANSFER GROUP
 Jmp,bcc,dbcc,scc,nop,stop
 STACK CONTROL INSTRUCTION
 SUBROUTINE CONTROL INSTRUCTION
 jsr,bsr,rts,rtr
 Assembler directives are not executed during program execution.
 ORG :




– instruct the assembler to assemble the program.
– initiate the address of the first instruction.
– ORG
$1000
END
– terminate the assembly process.
EQU
– assign value
– COUNTER EQU $30
DC
– reserve memory with initial values.
– DATA
DC.B $32,$65,$21,$33
DS
– reserve memory with no initial values
– SUM
DS.B 6
TOTAL DS.W 1
SLIDE 11
 Carry, C
 oVerflow, V
 For operation with 2’s complement.
 (+ve) + (+ve) = (-ve)  V = 1 (salah)
 (+ve) + (+ve) = (+ve)  V = 0 (betul)
 oVerflow, V
 For operation with 2’s complement.
 (-ve) - (+ve) = (+ve)  V = 1
 oVerflow, V
 For operation with 2’s complement.
 (-ve) - (+ve) = (-ve)  V = 0
 (-ve) - (-ve) = (+ve)  V = 0
 Zero, Z
 Result zero; Z = 1
 Result not zero; Z = 0
 Negative, N
 Result negative; N = 1
 Result positive; N = 0
 Extend (X)
 Usually copy C flag.
 Use in multiple precision arithmetic (aritmetik titik apungan).
 Interrupt mask bits (I2,I1,I0)
 Trace, T
 T = 1, Instructions will be execute step by step.
 T = 0, Instructions will be execute till the end.
 Supervisor, S
 S = 1, processor in supervisor state, all instruction can be executed.
 S = 0, processor in user state, executing privileged instruction will
cause trap.
Related documents