3 0 INTRODUCTION Message sent by programmers program


3. 0 INTRODUCTION 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

3. 0 INTRODUCTION

3. 1 HLL, AL, ML 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.

3. 1 HLL, AL, ML 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.

3. 1 HLL, AL, ML

3. 1 HLL, AL, ML

3. 2 ASSEMBLY LANGUAGE PROGRAMING ASM 68 K

3. 2 ASSEMBLY LANGUAGE PROGRAMING

3. 2. 1 MACHINE INSTRUCTION / CODE FORMAT

3. 3 INSTRUCTION FORMAT There are many MC 68000 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

3. 3 INSTRUCTION FORMAT Operator. a mnemonic code for MC 68000 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

3. 4. 1 DATA TRANSFER / MOVE GROUP Transfer / move data between registers and memory. Instructions of data transfer group. MOVE. B D 1, D 2 MOVE. B D 6, CCR MOVE. W SR, D 6 MOVE. L USP, A 1 MOVE. L A 2, USP MOVEA. W #$4321, A 0 MOVEQ. B #01, D 4 MOVEM. W D 2/D 4 -D 6, $4000 MOVEM. L $4000, D 0 -D 5 LEA START, A 0 EXG SWAP CLR. B D 1, D 2 D 3 $3000

3. 4. 1 MOVE Byte(B), Word(W) and Long word(L). R�R , R�M , M�M , EA�SR , USP�An Example 1: MOVE. W #$72, D 1 Before : D 1 = $00200500 After : D 1 = $00200072 # menunjukkan data sebenar. $ menunjukkan nombor heksa Example 2: MOVE. B D 0, D 1 Before : D 1 = $00200500 , D 0 = $00002222 After : D 1 = $00200522 , D 0 = $00002222 Example 3: MOVE. B $3000, D 1 Before : D 1 = $00200500 , After : D 1 = $00200532 , $3000 32 $3001 43 $3002 98

3. 4. 1 MOVE(CONT. ) Example 4: $4000 3254 $4000 32 MOVE. W D 6, $4000 $4002 4377 @ $4001 54 Before: D 6 = $AB 206541 , $4004 9868 $4002 43 After : D 6 = $AB 206541 , Example 5: $4000 6541 $4002 4377 $4004 9868 @ $4000 65 $4001 41 $4002 43 MOVEA. W D 6, A 2 Before : D 6 = $AB 206541 , A 2 = $ABCD 1234 After : D 6 = $AB 206541 , A 2 = $00006541 Example 6: MOVEA. W D 6, A 2 Before : D 6 = $AB 20 A 541 , A 2 = $ABCD 1234 After : D 6 = $AB 206541 , A 2 = $FFFFA 541

3. 4. 1 MOVE(CONT. ) Example 7: MOVEA. L D 6, A 2 Before : D 6 = $AB 206541 , A 2 = $ABCD 1234 After : D 6 = $AB 206541 , A 2 = $AB 206541 Example 8: -128 (80) hingga 127 (7 F) MOVEQ #$04, D 3 (MOVEQ #XXX, Dn) Before : D 3 = $AB 206541 After : D 3 = $00000004 Example 9: MOVEQ #$80, D 3 Before : D 3 = $AB 206541 After : D 3 = $FFFFFF 80

3. 4. 1 MOVE(CONT. ) Example 10: MOVEM. W D 2/D 5/D 0, $200 Before : D 0 = $11112222 , $200 6541 D 2 = $33334444 , $202 4377 D 5 = $55556666 , $204 9868 After : D 0 = $11112222 , $200 4444 D 2 = $33334444 , $202 6666 D 5 = $55556666 , $204 2222 Example 11: Predecrement (tolak dulu) B: – 1, W: – 2, L: – 4 Dlm contoh ada 3 daftar maka 3 x 4=12 , 50 C – C = 500 MOVEM. L D 2/D 5/D 0, -(A 4) Before : D 0 = $11112222 , D 2 = $33334444 , $500 451287 A 4 $504 54 A 2 F 221 D 5 = $55556666 , A 4 = $0000050 C After : D 0 = $11112222 , $500 33334444 D 2 = $33334444 , $504 55556666 D 5 = $55556666 , $508 11112222 A 4 = $00000500 $508 846 AC 1 DD $50 C 45123211

3. 4. 1 MOVE(CONT. ) Example 12: MOVEM. W $200, D 2/D 5/D 0 Before : D 0 = $11112222 , $200 6541 D 2 = $33334444 , $202 4377 D 5 = $55556666 , $204 9868 After : D 0 = $FFFF 9868 , $200 6541 D 2 = $00006541 , $202 4377 D 5 = $00004377 , $204 9868 Example 13: Posincrement (tmbh kmdn) B: +1, W: +2, L: +4 Dlm contoh ada 3 daftar maka 3 x 4=12 , 500 + C = 50 C MOVEM. L (A 4)+, D 2/D 5/D 0 Before : D 0 = $1111222 , D 2 = $33334444 , $500 451287 A 4 $504 54 A 2 F 221 D 5 = $55556666 , A 4 = $00000500 After : D 0 = $846 AC 1 DD , $500 451287 A 4 D 2 = $451287 A 4 , $504 54 A 2 F 221 D 5 = $54 A 2 F 221 , $508 846 AC 1 DD A 4 = $0000050 C $508 846 AC 1 DD $50 C 45123211

3. 4. 1 MOVE(CONT. ) Example 14: MOVEP. W D 2, 1(A 1) Before : D 2 = $AB 206541 , A 1 = $00000501 After : D 2 = $AB 206541 , A 1 = $00000501 Example 15: $501 FF $502 FF $503 FF $501 FF $502 65 $503 41 $502 dan $501 adalah alamat I/O EXG D 1, D 5 Before : D 1 = $11223344 , D 5 = $66778899 After : D 1 = $66778899 , D 5 = $11223344 Example 16: SWAP D 1 Before : D 1 = $11223344 After : D 1 = $33441122

3. 4. 1 MOVE(CONT. ) Example 17: OPER EQU $2001 MOVEA. L OPER #OPER, A 1 MOVEA. L #$2001, A 1 After : A 1 = $00002001 EQU LEA $2001 OPER, A 1 LEA $2001, A 1 MOVEA. L $2001, A 1 ≠ LEA $2001, A 1 Example 18: CLR. B D 1 Before : D 1 = $11223344 After : D 1 = $ 11223300

3. 4. 2 ARITHMETIC ADD. W ADD. L ADDI. B ADDQ. W ADDX ADDA SUB. W SUB. L SUBI. B SUBQ. W SUBX SUBA NEGX MULS MULU DIVS DIVU EXT. W EXT. L $300, D 1 D 2, $218 #$44, D 3 #$32, D 2 D 1, D 2 -(A 1), -(A 3) $100, A 6 D 1 A 4 $32, D 5 #$04, D 5 D 3 D 2

3. 4. 2 ARITHMETIC(CONT. ) Byte(B), Word(W) and Long word(L). Data via register, memory, absolute data and I/O port. Example 1: ADDI. W #$72, D 1 Before : D 1 = $00200500 After : D 1 = $00200572 Example 2: ADD. L D 0, D 1 Before : D 1 = $00200500 , D 0 = $00002222 After : D 1 = $00202722 , D 0 = $00002222 Example 3: ADD. W $3000, D 1 Before : D 1 = $00200500 , After : D 1 = $00203743 , $3000 32 $3001 43 $3002 98

3. 4. 2 ARITHMETIC(CONT. ) Example 4: $4000 3254 $4000 32 ADD. W D 6, $4000 $4002 4377 @ $4001 54 Before: D 6 = $AB 206541 , $4004 9868 $4002 43 After : D 6 = $AB 206541 , Example 5: $4000 9795 $4002 4377 $4004 9868 @ $4000 97 $4001 95 $4002 43 ADDA. W D 6, A 2 Before : D 6 = $AB 206541 , A 2 = $ABCD 1234 After : D 6 = $AB 206541 , A 2 = $ABCD 7775 Example 6: ADDA. L D 6, A 2 Before : D 6 = $AB 20 A 541 , A 2 = $ABCD 1234 After : D 6 = $AB 206541 , A 2 = $56 EDB 775 , C = 1

3. 4. 2 ARITHMETIC(CONT. ) Example 7: ADDX. B D 2, D 3 Before : D 2 = $AB 206541 , D 3 = $ABCD 1234 , X = 1 After : D 2 = $AB 206541 , D 3 = $AB 206576 , X = 1 Example 8: -128 (80) hingga 127 (7 F) ADDQ. B #$04, D 3 (ADDQ #XXX, Dn) Before : D 3 = $AB 206541 After : D 3 = $AB 206545 Example 9: SUB. W #$80, D 3 Before : D 3 = $AB 206541 After : D 3 = $AB 2064 C 1

3. 4. 2 ARITHMETIC(CONT. ) Example 10: @ menunjukkan nombor octal % menunjukkan nombor binari SUBI. L #10, D 2 Before : D 2 = $AB 206541 After : D 2 = $AB 206537 Example 11: SUBQ. W #@11, D 3 (SUBQ #XXX, Dn) Before : D 3 = $AB 206541 -128 (80) hingga 127 (7 F) After : D 3 = $AB 200038 Example 12: NEG. W D 3 NEG = Pelengkap 2 Before : D 3 = $AB 206541 $41 = Songsangkan After : D 3 = $AB 209 ABF $BF = 01000001 10111110 + 1 10111111

3. 4. 2 ARITHMETIC(CONT. ) Example 13: MULU #2, D 2 ; 16 bit x 16 bit = 32 bit Before : D 2 = $AB 206541 After : D 2 = $0000 CA 82 Example 11: MULU #2, D 2 @ menunjukkan nombor octal % menunjukkan nombor binari Before : D 2 = $AB 20 FFFF After : D 2 = $0001 FFFE Example 12: DIVU #2, D 3 ; 32 bit / 16 bit = 16 bit lower (result) 16 bit upper ( remainder) Before : D 3 = $00006541 F = 25921 After : D 3 = $000132 A 016 = 1296010

3. 4. 3 LOGICAL OPERATION AND. W AND. L ANDI. B ANDI ADDI $300, D 1 D 2, $218 #$44, D 3 #%11011, CCR #$25, SR OR. W OR. L ORI. B ORI $300, D 1 D 2, $218 #$44, D 3 #%11011, CCR #$25, SR EOR. W EORI. B EORI $300, D 1 #$44, D 3 #%11011, CCR #$25, SR NOT. W D 2

3. 4. 3 LOGICAL OPERATION(CONT. ) Example 1: AND. B #$3 E, D 1 Before : D 1 = $12345674 After : D 1 = $12345634 Example 2: OR. B D 0, D 1 Before : D 1 = $1234563 E , D 0 = $98765474 After : D 1 = $1234567 E , D 0 = $98765474 Example 3: NOT. B D 1 Before : D 1 = $12345655 , After : D 1 = $123456 AA ,

3. 4. 4 SHIFT AND ROTATE Example 4: B : 0 to 255 | $00 - $FF

3. 4. 4 SHIFT AND ROTATE (CONT. ) Example 5: B : 0 to 255 | $00 - $FF

3. 4. 4 SHIFT AND ROTATE (CONT. ) Example 6: B : 0 to 255 | $00 to $FF

3. 4. 4 SHIFT AND ROTATE (CONT. ) Example 7: B : 0 to 255 | $00 to $FF

3. 4. 4 SHIFT AND ROTATE (CONT. ) Example 8: B : 0 to 127 | $00 - $7 F -1 to -128 | $FF to $8 F

3. 4. 4 SHIFT AND ROTATE (CONT. ) Example 9: B : 0 to 127 | $00 - $7 F -1 to -128 | $FF to $8 F

3. 4. 4 SHIFT AND ROTATE (CONT. ) Example 10:

3. 4. 5 CONTROL TRANSFER 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 $8 A 50 PC is a 32 bit register.

3. 4. 5 CONTROL TRANSFER Conditional transfer instruction i. Bcc instruction (Branch conditionally) Format: Bcc DST Example: START MOVE. W D 3, D 4 …. . BNE NEXT ; (Branch if Z=0) NEG D 3 …. NEXT SUB. W #32, D 1

3. 4. 5 CONTROL TRANSFER 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 D 4 ; D 4 = $0000 …. . DBNE D 4, NEXT ; condition (Z=0) NEG D 3 …. NEXT SUB. W#32, D 1

3. 4. 5 CONTROL TRANSFER iii. Scc instruction (set conditionally) Format: Scc DST Operation: Test condition: i. condition met; DST will get 1 s ii. condition not met; DST will get 0 s No branch involved. Example: START CLR. L D 4 ; Z = 1 SNE D 5 ; D 5 = $0000

3. 4. 5 CONTROL TRANSFER 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

3. 4. 6 STACK CONTROL Stack is a data structure that can be used to save data. Stack works in LIFO concept.

3. 4. 6 STACK CONTROL There are two (2) stack: User Stack – point by USP & Supervisor Stack – point by SSP

3. 4. 6 STACK CONTROL PUSH data into stack. 1. decrement SP 2. move data into stack MOVE. B D 1, -(A 0) POP data from stack. 1. move data from stack 2. increment SP MOVE. B (A 0)+, D 1

3. 4. 7 SUBROUTINE CONTROL 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

3. 4. 7 SUBROUTINE CONTROL JSR EA – the subroutine maybe anywhere in the memory. Operation: �PC -(SP) �EA PC BSR EA – the subroutine must be within 65536 address Operation: �PC -(SP) �PC + d PC

3. 4. 7 SUBROUTINE CONTROL RTS – return from subroutine Operation: �(SP)+ PC RTR – return and restore CCR Operation: �(SP)+ CCR �(SP)+ PC

REVISION 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

3. 4. 8 ASSEMBLER DIRECTIVES Assembler directives are not executed during program execution. ORG : – instruct the assembler to assemble the program. SLIDE 11 – 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

3. 4. 8 ASSEMBLER DIRECTIVES

3. 4. 8 ASSEMBLER DIRECTIVES

3. 5 FLAG/STATUS REGISTER

3. 5 FLAG/STATUS REGISTER (CONT. ) Carry, C

3. 5 FLAG/STATUS REGISTER (CONT. ) o. Verflow, V For operation with 2’s complement. (+ve) + (+ve) = (-ve) � V = 1 (salah) (+ve) + (+ve) = (+ve) � V = 0 (betul)

3. 5 FLAG/STATUS REGISTER (CONT. ) o. Verflow, V For operation with 2’s complement. (-ve) - (+ve) = (+ve) � V=1

3. 5 FLAG/STATUS REGISTER (CONT. ) o. Verflow, V For operation with 2’s complement. (-ve) - (+ve) = (-ve) � V=0 (-ve) - (-ve) = (+ve) � V=0

3. 5 FLAG / STATUS REGISTER Zero, Z Result zero; Z = 1 Result not zero; Z = 0

3. 5 FLAG / STATUS REGISTER Negative, N Result negative; N = 1 Result positive; N = 0 Extend (X) Usually copy C flag. Use in multiple precision arithmetic (aritmetik titik apungan).

3. 5 FLAG / STATUS REGISTER Interrupt mask bits (I 2, I 1, I 0) 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.
- Slides: 58