580 likes | 596 Views
Understand machine language, assembly language, and high-level language in electronic system programming. Learn about HLL, AL, ML, and instruction formats. Includes examples of data transfer and move instructions.
E N D
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.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.3 INSTRUCTION FORMAT • 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
3.3 INSTRUCTION FORMAT • Operator . • a mnemonic code for MC68000 instructions . • An assembler directive / pseudo-instruction / pseudo-operation. • Macro call (repetitive instructions in a program which arecodified 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 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 D1,D2 SWAP D3 CLR.B $3000
3.4.1 MOVE # menunjukkan data sebenar. $ menunjukkannomborheksa • 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 • 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 ,
3.4.1 MOVE(CONT.) @ • Example 4: • MOVE.W D6,$4000 • Before: D6 = $AB206541 , • After : D6 = $AB206541 , • Example 5: • 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 @
3.4.1 MOVE(CONT.) • Example 7: • MOVEA.L D6,A2 • Before : D6 = $AB206541 , A2 = $ABCD1234 • After : D6 = $AB206541 , A2 = $AB206541 • Example 8: • MOVEQ #$04,D3 (MOVEQ #XXX,Dn) • Before : D3 = $AB206541 • After : D3 = $00000004 • Example 9: • MOVEQ #$80,D3 • Before : D3 = $AB206541 • After : D3 = $FFFFFF80 -128 (80) hingga 127 (7F)
3.4.1 MOVE(CONT.) • Example 10: • MOVEM.W D2/D5/D0,$200 • Before : D0 = $11112222 , D2 = $33334444 , D5 = $55556666 , • After : D0 = $11112222 , D2 = $33334444 , D5 = $55556666 , • Example 11: • MOVEM.L D2/D5/D0,-(A4) • Before : D0 = $11112222 , D2 = $33334444 , D5 = $55556666 , A4 = $0000050C • After : D0 = $11112222 , D2 = $33334444 , D5 = $55556666 , A4 = $00000500 Predecrement (tolakdulu) B : – 1 , W : – 2 , L : – 4 Dlmcontohada 3 daftarmaka 3x4=12 , 50C – C = 500
3.4.1 MOVE(CONT.) • Example 12: • MOVEM.W $200,D2/D5/D0 • Before : D0 = $11112222 , D2 = $33334444 , D5 = $55556666 , • After : D0 = $FFFF9868 , D2 = $00006541 , D5 = $00004377 , • Example 13: • MOVEM.L (A4)+,D2/D5/D0 • Before : D0 = $1111222 , D2 = $33334444 , D5 = $55556666 , A4 = $00000500 • After : D0 = $846AC1DD , D2 = $451287A4 , D5 = $54A2F221 , A4 = $0000050C Posincrement (tmbhkmdn) B : + 1 , W : + 2 , L : + 4 Dlmcontohada 3 daftarmaka 3x4=12 , 500 + C = 50C
3.4.1 MOVE(CONT.) $502 dan $501 adalahalamat I/O • Example 14: • MOVEP.W D2,1(A1) • Before : D2 = $AB206541 , A1 = $00000501 • After : D2 = $AB206541 , A1 = $00000501 • Example 15: • EXG D1,D5 • Before : D1 = $11223344 , D5 = $66778899 • After : D1 = $66778899 , D5 = $11223344 • Example 16: • SWAP D1 • Before : D1 = $11223344 • After : D1 = $33441122
3.4.1 MOVE(CONT.) OPER EQU $2001 MOVEA.L #OPER,A1 OPER EQU $2001 LEA OPER,A1 • Example 17: • After : A1 = $00002001 • MOVEA.L $2001,A1 ≠ LEA $2001,A1 • Example 18: • CLR.B D1 • Before : D1 = $11223344 • After : D1 = $ 11223300 MOVEA.L #$2001,A1 LEA $2001,A1
3.4.2 ARITHMETIC ADD.W $300,D1 ADD.L D2,$218 ADDI.B #$44,D3 ADDQ.W #$32,D2 ADDX D1,D2 ADDX -(A1),-(A3) ADDA $100,A6 SUB.W $300,D1 SUB.L D2,$218 SUBI.B #$44,D3 SUBQ.W #$32,D2 SUBX D1,D2 SUBX -(A1),-(A3) SUBA $100,A6 NEG D1 NEGX A4 MULS $32,D5 MULU #$04,D5 DIVS $32,D5 DIVU #$04,D5 EXT.W D3 EXT.L D2
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,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 ,
3.4.2 ARITHMETIC(CONT.) @ • Example 4: • ADD.W D6,$4000 • Before: D6 = $AB206541 , • After : D6 = $AB206541 , • Example 5: • 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 @
3.4.2 ARITHMETIC(CONT.) • Example 7: • ADDX.B D2,D3 • Before : D2 = $AB206541 , D3 = $ABCD1234 , X = 1 • After : D2 = $AB206541 , D3 = $AB206576 , X = 1 • Example 8: • 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 -128 (80) hingga 127 (7F)
@ menunjukkannombor octal % menunjukkannomborbinari 3.4.2 ARITHMETIC(CONT.) • Example 10: • SUBI.L #10,D2 • Before : D2 = $AB206541 • After : D2 = $AB206537 • Example 11: • SUBQ.W #@11,D3 (SUBQ #XXX,Dn) • Before : D3 = $AB206541 • After : D3 = $AB200038 • Example 12: • NEG.W D3 • Before : D3 = $AB206541 • After : D3 = $AB209ABF -128 (80) hingga 127 (7F) NEG = Pelengkap 2 $41 = 01000001 Songsangkan 10111110 + 1 $BF = 10111111
3.4.2 ARITHMETIC(CONT.) @ menunjukkannombor octal % menunjukkannomborbinari • Example 13: • MULU #2,D2 ;16 bit x 16 bit = 32 bit • Before : D2 = $AB206541 • After : D2 = $0000CA82 • Example 11: • MULU #2,D2 • 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 • After : D3 = $000132A0 6541F = 25921 32A016 = 1296010
3.4.3 LOGICAL OPERATION AND.W $300,D1 AND.L D2,$218 ANDI.B #$44,D3 ANDI #%11011,CCR ADDI #$25,SR OR.W $300,D1 OR.L D2,$218 ORI.B #$44,D3 ORI #%11011,CCR ORI #$25,SR EOR.W $300,D1 EORI.B #$44,D3 EORI #%11011,CCR EORI #$25,SR NOT.W D2
3.4.3 LOGICAL OPERATION(CONT.) • 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 ,
3.4.4 SHIFT AND ROTATE B : 0 to 255 | $00 - $FF • Example 4:
3.4.4 SHIFT AND ROTATE (CONT.) B : 0 to 255 | $00 - $FF • Example 5:
3.4.4 SHIFT AND ROTATE (CONT.) B : 0 to 255 | $00 to $FF • Example 6:
3.4.4 SHIFT AND ROTATE (CONT.) B : 0 to 255 | $00 to $FF • Example 7:
3.4.4 SHIFT AND ROTATE (CONT.) B : 0 to 127 | $00 - $7F -1 to -128 | $FF to $8F • Example 8:
3.4.4 SHIFT AND ROTATE (CONT.) B : 0 to 127 | $00 - $7F -1 to -128 | $FF to $8F • Example 9:
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 $8A50 • 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 D3,D4 ….. BNE NEXT ;(Branch if Z=0) NEG D3 …. NEXT SUB.W #32, D1
3.4.5 CONTROL TRANSFER ii. DBcc instruction (test condition, decrement & branch) Format: DBccDn,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
3.4.5 CONTROL TRANSFER 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
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 D1,-(A0) • POP data from stack. • 1. move data from stack 2. increment SP • MOVE.B (A0)+,D1
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 • 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
3.4.7 SUBROUTINE CONTROL • RTS • RTS – return from subroutine • Operation: • (SP)+ PC • RTR • 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 SLIDE 11 • 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