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,

Slides:



Advertisements
Similar presentations
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Advertisements

Machine/Assembler Language Putting It All Together Noah Mendelsohn Tufts University Web:
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 2 Department of Computer Science and Software Engineering University of Wisconsin-Platteville.
ICS312 Set 6 Operands. Basic Operand Types (1) Register Operands. An operand that refers to a register. MOV AX, BX ; moves contents of register BX to.
ACOE2511 Assembly Language Arithmetic and Logic Instructions.
Computer Organization & Assembly Language
Introduction to Assembly Here we have a brief introduction to IBM PC Assembly Language –CISC instruction set –Special purpose register set –8 and 16 bit.
Assembly 02. Outline mov Command Registers Memory EFLAGS Arithmetic 1.
Multiplication and Division
KMUTT: S. Srakaew Instructions Can Be Divided into 3 Classes Data movement instructions  Move data from a memory location or register to another memory.
Target Processor Directives , When using.386, the program can only run on 386 and above processors.
Kip Irvine: Assembly Language for Intel-Based Computers
Review Questions Chapters What TUTOR command is used to enter a string of ASCII bytes into memory? /MA 2.What are the names of the 8086 index.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
Chapter 1: Basic Concepts
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Types of Registers (8086 Microprocessor Based)
Multiplication and Division Instructions & the 0Ah function.
Microprocessors Monday, Apr. 13 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Assembly Code Optimization Techniques for the AMD64 Athlon and Opteron Architectures David Phillips Robert Duckles Cse 520 Spring 2007 Term Project Presentation.
Arithmetic Flags and Instructions
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Introduction Arithmetic instructions are used to perform arithmetic operation such as Addition Subtraction Multiplication Division These operations can.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
Microprocessors CSE- 341 Dr. Jia Uddin Assistant Professor, CSE, BRAC University Dr. Jia Uddin, CSE, BRAC University.
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
Computer Architecture and Assembly Language
Microprocessor Systems Design I
Microprocessor and Assembly Language
Microprocessor and Assembly Language
Assembly IA-32.
Microprocessor Lab CSL1543 0:0:2
(The Stack and Procedures)
9/17/2018 Kiến Trúc Máy Tính.
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
X86’s instruction sets.
Introduction to Assembly Language
BIC 10503: COMPUTER ARCHITECTURE
Data Addressing Modes • MOV AX,BX; This instruction transfers the word contents of the source-register(BX) into the destination register(AX). • The source.
Microprocessor and Assembly Language
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(The Stack and Procedures)
Shift & Rotate Instructions)
Multiplication and Division Instructions
Symbolic Instruction and Addressing
Computer Architecture CST 250
X86 Assembly Review.
COMP2012H: OOP and DS (honors track)
Chapter 6 –Symbolic Instruction and Addressing
Process.
(The Stack and Procedures)
CS-401 Computer Architecture and Assembly Language Programming
Introduction to Assembly
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Presentation transcript:

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, 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

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

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 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

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 Inline Code in C Links to get help with Inline code: – in Swedish: –use the search function on Inline Assembly Links to other assembly language topics NY.htm (in Swedish)

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 # 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 /* 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 */ }