Presentation is loading. Please wait.

Presentation is loading. Please wait.

PC-technology MASM and Inline Code in C. PC-Teknik © CAAK2 MASM and Inline Code in C Some things to think about –Which size has the register you use AX,

Similar presentations


Presentation on theme: "PC-technology MASM and Inline Code in C. PC-Teknik © CAAK2 MASM and Inline Code in C Some things to think about –Which size has the register you use AX,"— Presentation transcript:

1 PC-technology MASM and Inline Code in C

2 PC-Teknik © CAAK2 MASM and Inline Code in C Some things to think about –Which size has the register you use AX, AH, AL MOV AX, 500Max 16 bits MOV AH, 5Max 8 bits MOV AL,2Max 8 bits Now AX holds 0502H (1282 decimal) –OUT always uses the accumulator, AX in older versions of processors, only lower byte, AL

3 PC-Teknik © CAAK3 MASM and Inline Code in C Some things to think about, cont. –MUL always works on AX MUL BLBL*AL the result in AX MUL BXBX*AX the result in DX:AX –DX*65536+AX because DX holds the 16 higher bits and AX the lower 16 bits –When working with.exe-files, the code and data have to be placed in separate segments

4 PC-Teknik © CAAK4 One solution to the Organ Make an array of the numbers to divide the clock frequency with: –TONE DW 0, 0E24h, 11D1h, 0, 0, 10D0h, 0EFBh,0 –The first one is used when character A is pressed, the next, the 0E24H when B is pressed, and 11D1H gives the tone C when C is pressed.

5 5 One solution to the Organ How do you get the right address? –Ex. You press the C and want the tone C to sound. C has the ASCII code 67 and A has the code 65 If you take ‘A’-65 you get 0 If you take ‘C’-65 you get 2 When you go into the array the first number in the array is at address TONE + 0, the next at address TONE+2, the next at TONE+4 => if C is pressed you want to goto address 2*2 which is (‘C’-65)*2 MOV BH,0 ;empty high byte of BX SUB BX,'A' ;ASCII-code - 65 ADD BX,BX; (ASCII code-65) * 2

6 PC-Teknik © CAAK6 One solution to the Organ How do you get the right address? –To point at address TONE: MOV SI,OFFSET TONE –To point at the first byte of number corresponding to ‘C’ –MOV AL,DS:[SI+BX]

7 7 Inline Code in C Links to get help with Inline code: –http://www.microsoft.com/ in Swedish: http://www.microsoft.com/sverige/ –use the search function on Inline Assembly Links to other assembly language topics http://www.jorgon.freeserve.co.uk/ http://home6.swipnet.se/~w-61969/asm/ASM- NY.htm (in Swedish) http://www.jegerlehner.ch/intel/ http://brianvictor.8m.com/

8 8 Inline Code in C Usage –need a piece of program that runs faster than the C-code –and want to use C code to type things onto the screen –want to use the data segment in the same way as in C Examples at MSDN

9 9 # include void main(void) { unsigned short number1, number2, regAX, regDX; long int product; number1=500; number2=500; _asm { mov ax,number1 mov bx,number2 mul bx mov regAX,ax mov regDX,dx } cout<<regAX<<endl; cout<<regDX<<endl; product = regAX+65536*(long)regDX; cout<<product; }

10 10 /* POWER2.C */ #include int power2( int num, int power ); void main( void ) { printf( "3 times 2 to the power of 5 is %d\n", \power2( 3, 5) ); } int power2( int num, int power ) { __asm { mov eax, num ; Get first argument mov ecx, power ; Get second argument shl eax, cl ; EAX = EAX * ( 2 to the power of CL ) } /* Return with result in EAX */ }


Download ppt "PC-technology MASM and Inline Code in C. PC-Teknik © CAAK2 MASM and Inline Code in C Some things to think about –Which size has the register you use AX,"

Similar presentations


Ads by Google