Presentation is loading. Please wait.

Presentation is loading. Please wait.

CPU12 Instruction Set Overview

Similar presentations


Presentation on theme: "CPU12 Instruction Set Overview"— Presentation transcript:

1 CPU12 Instruction Set Overview
Reading Assignment: Huang Ch 4 CPU12 Manual 4/17/2018

2 Load from memory into CPU regs
4/17/2018

3 LEAX – Load Effective Address into X
4/17/2018

4 Examples of “Load Effective Address” Instructions
ORG $4020 Datalist: FCB $12, $34, $44, $46, $78 ORG $4675 FCB $90, $89, $67, $56, $34, #23 ORG $4000 LDY #Datalist LDX 3,Y ;Load $4678 into register X LDX [3,Y] ;Load $5634 into register X LEAX 3,Y ;Load $4023 into register X ;LEAX loads the effective addr ;of the data, not the data itself. LEAS 4,S ;SP + 4 -> SP ;Used to remove 4 bytes from stack! 4/17/2018

5 Storing from CPU registers to Memory
4/17/2018

6 Transfer and Exchange data between CPU Registers
4/17/2018

7 4/17/2018

8 SEX (Sign Extend) Example
SEX B,X ;Sign extend 8-bit nr in B into ;16-bit nr in X B->XLow and $FF -> XHigh if MSB(B) = 1 B->XLow and $00 -> XHigh if MSB(B) = 0 4/17/2018

9 4/17/2018

10 TFR Examples TFR B,X ;SEX B -> X TFR B,D ;SEX B ->A:B
TFR A,B ;A -> B TFR B,X ;SEX B -> X TFR B,D ;SEX B ->A:B TFR X,B ;XLow -> B TFR D,SP ;D -> SP 4/17/2018

11 4/17/2018

12 Examples XCHG EXG A,B ;A-> B and B-> A
EXG B,A ;B-> A and A -> B (no difference) EXG X,Y ;X -> Y and Y -> X EXG Y,X ;Y -> X and X -> Y (no difference) EXG A,X ;A -> XL and XL -> A, but $00 -> XH EXG X,A ;XL -> A and A -> XL, but $FF -> XH 4/17/2018

13 MOVE Instructions 4/17/2018

14 4/17/2018

15 Addition and Subtraction Instructions
4/17/2018

16 For multiple-precision addition, use ADDx to add the least significant byte position, and then use ADCx to add the rest of the byte positions, as you work your way up from leas significant byte position to most significant byte position. ORG $0400 RESULT: DS.B 5 ORG $4000 ADDEND: DC.B $12, $34, $56, $78, $98 AUGEND: DC.B $08, $AB, $CD, $EF, $AD Entry: CLRA LDAA ADDEND+4 ADDA AUGEND+4 ;Use “ADDA” when adding least sig. bytes STAA RESULT+4 LDAA ADDEND+3 ADCA AUGEND+3 ;Use “ADCA” (add with carry) STAA RESULT+3 ;when adding all remaining bytes. …. ETC…. 4/17/2018

17 ABA, ABX example LDX #$CDEF ABA ;D = $4634 ABX ;D = $CDEF + $0034
LDD #$1234 ;D = A:B LDX #$CDEF ABA ;D = $4634 ABX ;D = $CDEF + $0034 ;Thus D = $CE23 4/17/2018

18 Binary Coded Decimal (BCD) Addition Instructions
Ex: LDAA #$ ADDA #$27 A = $8F ;Normal Binary Addition Result DAA A = $95 ;Adjusted BCD Result ($8F+$06=$95) ;Note: DAA adds “6” to least sig 4 bits if H=1 or result > ; and it adds “6” to most sig 4 bits if C = 1 or result > 9 4/17/2018

19 Increment and Decrement Instructions: Note: they affect N, Z, V flags, but not C Flag so they can be used for looping in multiple precision calculations. 4/17/2018

20 4/17/2018

21 Compare and Test Instructions
They subtract, set the condition code flags ZNVC. The “difference” result is not stored. These instructions are typically followed by a conditional branch instruction that branches off of the way the resulting flag setting 4/17/2018

22 4/17/2018

23 Compare Example LDAA PTT CMPA #45
BGT OVER_45 ;Branch to “OVER_45” if Port T ;contains a binary value that ;is greater than 45 in a signed ;two’s complement sense. . UNDER_46: NOP …… OVER_45: NOP 4/17/2018

24 Boolean Logic (Bit-by-bit) AND, EOR and OR
ANDA #% ; Force (mask) all bits in A to 0 except Bits 2 and 4 unchanged. EORA #% ; Invert bits 2 and 4, leaving rest of bits unchanged ORAA #% ; Force all bits in A to 1 except Bits 2 and 4 unchanged ORCC #% ; CCR=SXHINZVC. Force N, V, and C to 1. Rest unchanged. 4/17/2018

25 Clear, Complement, Negate Instructions
4/17/2018

26 Multiplication and Division Instructions
4/17/2018

27 Multiply & Divide Examples
LDAA #4 LDAB #6 MUL ;D = A*B = 24 LDX #10 IDIV ;D = Rmdr(D/X) = 4 ;X = D/X = 2 ; ;Note dividing by 10 breaks an 8-bit binary ;number up into its two decimal digits! LDD #24 FDIV ;X extracts first 16 bits of FRACTIONAL part of D/X ; (D must be < X) ;Note 24/10 = % ;(0.4 = 1/4+1/8+1/64+1/128 = ) ;Result of FDIV is X = LDD #$FFFF LDY #4 EMUL ;Y*D-> Y:D (unsigned numbers) ;65535*4 = =>Y = $3, D = $FFFC EMULS ;Y*D -> Y:D (signed numbers) ;-1 * 4 = -4 => Y = $FFFF, D = $FFFC 4/17/2018

28 Shift and Rotate Instructions
4/17/2018

29 Arithmetic vs. Logical Shift
Logical shift used for simulating a shift register to serially shift parallel data one bit at a time into, our out of, an I/O pin, or for multiplying or dividing UNSIGNED binary numbers by two. Arithmetic shift used for multiplying or dividing SIGNED (2’s complement) binary numbers by two. There are THREE forms of of shifts: shift memory, shift A, shift B Example: (LSL $1000, LSLA, LSLB) LSL (logical shift left) and ASL (arithmetic shift left) instructions are exactly the SAME: They both shift a zero into the LSB and shift the rest of the bits to the left to multiply a signed number by two. The MSB goes into the carry flag “C”. Examples: if A = % = 5, LSLA => A = % = 10 if A = % = -2, LSLA => A = % = -4 if A = % = 5, ASLA => A = % = 10 if A = % = -2, ASLA => A = % = -4 4/17/2018

30 If A = %00010101 = 21, then LSRA => A = %00001010 = 10
LSR (and ASR) are used to divide unsigned (and signed) numbers by two. To DIVIDE an unsigned number by two, LSR must shift a zero into the MSB, and the rest of the bits are shifted to the right. If A = % = 21, then LSRA => A = % = 10 If A = % = 254, then LSRA => A=% = 127 BUT to DIVIDE a signed (2’s complement) number by two, ASR must shift the MSB of the number to be shifted, and shift the rest of the bits are shifted to the right. If A = % = 21, then ASRA => A = % = 10 If A = % = -2, then ASRA => A=% = -1 If A = % = -8, then ASRA => A =% = -4 Therefore LSL and ASL are exactly the same instruction (same OP CODE!), but LSR and ASR are different instructions, and hence have different OP CODEs. 4/17/2018

31 Example: 24-bit Shift Left
C <- LOC2 <- LOC1 <- LOC0 <- 0 ORG $400 ;Start of RAM LOC2: RMB 1 ;High byte of 24-bit number LOC1: RMB 1 ;Middle byte of 24-bit number LOC0: RMB 1 ;Low byte of 24-bit number ORG $ ;Start of Flash ROM …… LSL LOC C <- LOC0 <- 0 ROL LOC C <- LOC1 <- C ROL LOC C <- LOC2 <- C 4/17/2018

32 Fuzzy Logic Instructions
HC12 includes high-level instructions tailor made for implementing fuzzy logic controllers 4/17/2018

33 Brief of Overview of Fuzzy Logic Instructions
MEM – Membership Function classifies an input value into a membership class REV and REVW - Unweighted and weighted min-max rule evaluation WAV and WAVR – Weighted Average and Resume Weighted Average (after an interrupt) 4/17/2018

34 Min-Max instructions (8 and 16-bit)
MINA $3800 ; puts contents of A or contents of $3800 into A, whichever is smallest in an unsigned sense EMAXM $3800 ; puts contents of D or contents of $3800:$3801 into $3800:$3801, whichever is larger in an unsigned sense. EMACS – 16X16 multiply and accumulate instruction, accumulates 32-bit result (useful in digital filter routine or defuzzification routine). If X = $3900 and Y = $3A00 EMACS $3800 ; ($3900:$3901) X ($3A00:$3A01) + ($3800:$3803) -> ; $3800:$3803 4/17/2018

35 (TBL & ETBL) Table Interpolation Instruction
4/17/2018

36 Bxx – Short Branch Instructions with 8-bit PC Relative Offset
4/17/2018

37 LBxx Long Branch Instructions with 16-bit PC-Relative Offset
4/17/2018

38 ; BGE vs BHS example: Finding largest number
; Use BHS for finding largest UNSIGNED nr ($FE) ; Use BGE for finding largest SIGNED nr ($78) XDEF Entry ABSENTRY Entry ORG $ ;Start of RAM Greatest: DS.B 1 ORG $4000 ;Start of Flash ROM DataTable: DC.B $12,$AB,$FE,$78,$CD,$00,$10,$FC,$00,$34 LengthTable:EQU 10 Entry: LDX #DataTable LDAA 0,X ;"A" holds greatest value NextElement: CMPA 1,X ;Find greatest UNSIGNED element BHS NoChangeA ;Change to BGE to find greatest ChangeA: ;SIGNED element. Branch if LDAA 1,X ; A>=(1+X) in an UNSIGNED sense! NoChangeA: INX ;Check next element CPX #DataTable + LengthTable - 1 BNE NextElement STAA Greatest ;Should hold "$FE" for BHS above Done: BRA Done ;Should hold "$78" if BHS changed to BGE. ORG $FFFE DC.W Entry ;Or use FDB directive 4/17/2018

39 Bit Condition Branch Instructions
Tests selected bit(s) and branches if selected bit(s) are either 0 or 1 Syntax: BRSET REG,mm,TARGET (branches to location TARGET if selected bits in “REG” are 1 (for BRSET) or are 0 (for BRCLR). Bits in REG are selected by the position of the 1’s in the MASK constant “mm”. 4/17/2018

40 Ex: Wait while switch on PT3 is high
1E FB WtHr: BRSET PTT,$08,WtHr This single instruction is equivalent to B WtHr: LDAA PTT ANDA #$08 26 F BNE WtHr Also note BRSET does not alter “A” or “CCR” 4/17/2018

41 Loop Primitive Instructions
4/17/2018

42 DBNE Example DBNE is used to loop back 8 times through the program, which in this case are simply two NOP instructions CE Entry: LDX #8 A LoopHr: NOP ;NOPs represent A NOP ;things to do 8 times….. 04 35 FB DBNE X,LoopHr “DBNE X,LoopHr” could be replaced by two instructions: DEX BNE LoopHr 4/17/2018

43 Jump and Subroutine Instructions
4/17/2018

44 Interrupt Instructions
4/17/2018

45 Software Interrupt Instruction (SWI) –causes interrupt using the $FFF6:$FFF7 interrupt vector
4/17/2018

46 Unimplemented OP CODE Instruction
4/17/2018

47 Index manipulation Instructions
4/17/2018

48 Stacking Instructions
4/17/2018

49 Pointer and Index Calculation Instructions
4/17/2018

50 LEAS example: Transferring arguments into subroutine via the stack
Entry: ;Example of a subroutine that adds 3 words ;Whose values are pushed on the stack, ;and the resulting sum is returned in register X lds #$1000 ;RAM block from $ $0FFF ldx #$1234 pshx ;Push input argument #1 ($1234) ldx #$4321 pshx ;Push input argument #2 ($4321) ldx #$2345 pshx ;Push input argument #3 ($2345) jsr add3wordsub leas 6,sp ;clean the 3 input words ;(6 bytes) off of the stack! stx result_sum done: bra done ;*****Subroutine "add3wordsub" starts here (register D is preserved). add3wordsub: pshd ;save D register, since it is altered in this rtn ldd # ;Stack Map: addd 8,SP ;(after pshd) 0fff 34 (Arg1_Lo) addd 6,SP ; SP+8-> 0ffe 12 (Arg1_Hi) addd 4,SP ; ffd 21 (Arg2_Lo) ; SP+6-> 0ffc 43 (Arg2_Hi) ; ffb 45 (Arg3_Lo) ; SP+4-> 0ffa 23 (Arg3_Hi) ; ff9 PClow tfr d,x ; ff8 PChigh (Return Addr) puld ; ff7 Dlow (b) rts ; SP-> 0ff6 Dhigh (a) 4/17/2018

51 Condition Code Instructions
4/17/2018

52 Stop and Wait Instructions
Both STOP and WAIT instructions wait for an interrupt to resume operation. STOP stops the clock oscillator, while WAIT does not. STOP puts processing in the lowest power consumption mode, but it takes longer to resume operation once interrupt occurs. 4/17/2018

53 Null Instructions 4/17/2018


Download ppt "CPU12 Instruction Set Overview"

Similar presentations


Ads by Google

玻璃钢生产厂家仿真玻璃钢雕塑小龙虾模型挂件江油玻璃钢十二生肖雕塑湘西玻璃钢雕塑中山动物雕塑玻璃钢图片晋中动物玻璃钢雕塑定做天津玻璃钢雕塑厂家湘西长沙玻璃钢雕塑厂家生产安徽公园玻璃钢雕塑定制商场连廊美陈外墙银川玻璃钢雕塑销售舞台道具商场美陈厂家玻璃钢人物雕塑效果图南京商场美陈玻璃钢卡通雕塑上海玻璃钢雕塑生产厂家甘南大型玻璃钢雕塑设计佛山玻璃钢彩色公仔雕塑玻璃钢卡通雕塑公仔定做西藏玻璃钢门头雕塑玻璃钢花盆可以种什么花鄂州玻璃钢雕塑熊猫哪家好玻璃钢雕塑需要哪些材料唐山玻璃钢人物雕塑兰州城市玻璃钢雕塑安装泰州商场新年美陈浙江玻璃钢海洋馆雕塑定做江苏树脂玻璃钢雕塑定做武汉商丘玻璃钢卡通雕塑2020上海商场圣诞美陈菏泽玻璃钢人物室外雕塑肇庆玻璃钢雕塑公司香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声单亲妈妈陷入热恋 14岁儿子报警汪小菲曝离婚始末遭遇山火的松茸之乡雅江山火三名扑火人员牺牲系谣言何赛飞追着代拍打萧美琴窜访捷克 外交部回应卫健委通报少年有偿捐血浆16次猝死手机成瘾是影响睡眠质量重要因素高校汽车撞人致3死16伤 司机系学生315晚会后胖东来又人满为患了小米汽车超级工厂正式揭幕中国拥有亿元资产的家庭达13.3万户周杰伦一审败诉网易男孩8年未见母亲被告知被遗忘许家印被限制高消费饲养员用铁锨驱打大熊猫被辞退男子被猫抓伤后确诊“猫抓病”特朗普无法缴纳4.54亿美元罚金倪萍分享减重40斤方法联合利华开始重组张家界的山上“长”满了韩国人?张立群任西安交通大学校长杨倩无缘巴黎奥运“重生之我在北大当嫡校长”黑马情侣提车了专访95后高颜值猪保姆考生莫言也上北大硕士复试名单了网友洛杉矶偶遇贾玲专家建议不必谈骨泥色变沉迷短剧的人就像掉进了杀猪盘奥巴马现身唐宁街 黑色着装引猜测七年后宇文玥被薅头发捞上岸事业单位女子向同事水杯投不明物质凯特王妃现身!外出购物视频曝光河南驻马店通报西平中学跳楼事件王树国卸任西安交大校长 师生送别恒大被罚41.75亿到底怎么缴男子被流浪猫绊倒 投喂者赔24万房客欠租失踪 房东直发愁西双版纳热带植物园回应蜉蝣大爆发钱人豪晒法院裁定实锤抄袭外国人感慨凌晨的中国很安全胖东来员工每周单休无小长假白宫:哈马斯三号人物被杀测试车高速逃费 小米:已补缴老人退休金被冒领16年 金额超20万

玻璃钢生产厂家 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化