Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECE 3561 - Lecture 1 1 L13a – Integer add Department of Electrical and Computer Engineering The Ohio State University ECE 2560.

Similar presentations


Presentation on theme: "ECE 3561 - Lecture 1 1 L13a – Integer add Department of Electrical and Computer Engineering The Ohio State University ECE 2560."— Presentation transcript:

1 ECE 3561 - Lecture 1 1 L13a – Integer add Department of Electrical and Computer Engineering The Ohio State University ECE 2560

2 Digital I/O on the 430 Integer addition For 8 bits For 16 bits For 32 bits Subroutine for 32 bit addition ECE 3561 - Lecture 1 2

3 8 bit addition The MSP 430 has instructions for 8 bit addition - all affect N,Z,C,V status bits - operations are on 8 bits only ADD.B src,dst Add source to destination src+dst  dst ADC.B dst Add carry to destination C+dst  dst ADDC.B src,dst Add source & carry to dest src+C+dst  dst SBC.B dst subtract C’ from destination SUB.B src,dst subtract source from destination SUBC.B src,dst subtract source & C from destination ECE 3561 - Lecture 1 3

4 16-bit addition The same as on the 8-bit addition slide except that the operation affects the entire word. The word stored in memory The 16 bits had the more significant byte stored at the higher address and the address of the data must be an even address. address +1 – msb byte base addr – low byte Memory dump in bytes xx xx ll hh yy yy Memory dump in words xxxx hhll yyyy ECE 3561 - Lecture 1 4

5 32 integer operations The MSP 430 does not support 32 bit data What to do? You the engineer must document the format and create the routines to work on the data. Define the data high wordMSW - stored at base address low word LSW - stored at base + 2 This will allow reading the value in a word display of memory. ECE 3561 - Lecture 1 5

6 32-bit addition Must define this in a subroutine as 32-bit data is not directly support in any instruction. Definition: In memory the data is stored in 2 consecutive words. The more significant word is stored at an even address and the least significant word is stored at this address +2. 0x0340 0001 4375 Would store the 32-bit value 0x00014375 ECE 3561 - Lecture 1 6

7 A routine to add 32-bit numbers ;data is passed on the stack Will use R4,R5,R6,R7 to do the addition so these must be saved. sra32pushSR pushR4 push R5 pushR6 pushR7 mov12(SP),R4 ;high word A mov14(SP),R5 ;low word A mov16(SP),R6 ;high word B mov18(SP),R7 ;low word B addR5,R7 addcR4,R6 ; R6-R7 is the answer movR6,16(SP) ;high word of answer movR7,18(SP) ;low word of answer popR7 popR6 popR5 pop R4 popSR ret ECE 3561 - Lecture 1 7

8 Subroutine is easy Subroutine is easy as it is just sequential code. No branches or decisions. Main routine must set up arguments on stack, do the call, store the result, clean up the stack. ECE 3561 - Lecture 1 8

9 Main routine ;code to test 32-bit add ;set up to call srm32 pushT1h pushT1l pushT2h pushT2l call#sra32 popR7 popR1h popR1l ;set up for 2 nd test endjmpend.data T1h.word0x0000 T1l.word0xFFFF T2h.word0x0000 T2l.word0x0001 R1h.word0x0000 R1l.word0x0000 ECE 3561 - Lecture 1 9

10 Enter the code assembler Enter the code and test it. Having a 32 bit add subroutine And shift and add multiply will now work on recursive subroutine call to do factorial. Demo of code with a few values. ECE 3561 - Lecture 1 10


Download ppt "ECE 3561 - Lecture 1 1 L13a – Integer add Department of Electrical and Computer Engineering The Ohio State University ECE 2560."

Similar presentations


Ads by Google