Lecture (03) x86 programming 2 By: Dr. Ahmed ElShafee ١ TOC The 80x86 Registers The Flag Register 80x86 Modes of operation ٢
Types of instruction set Complex instruction set computer (CISC): Large instruction set; Complex operations; Complex addressing modes; Complex hardware, long execution time; Minimum number of instructions needed for a given task; Easy to program, simpler compiler. ٣ Reduced instruction set computer (RISC): Small instruction set; Simple instructions to allow for fast execution (fewer steps); Large number of registers; Only read/write (load/store) instructions should access the main memory, one MM access per instruction; Simple addressing modes to allow for fast address computation; Fixed length instructions with few formats and aligned fields to allow for fast instruction decoding; increased compiler complexity and compiling time; ٤ simpler and faster hardware implementation, pipelined architecture.
> Memory Architecture Von Neumann: Common memory for data and instructions Harvard: Separate data and instruction memories ٥ > Von Neumann Memory Architecture ٦
> Harvard Memory Architecture ٧ > Difference between microcontroller and microprocessor Most of the microprocessors use CISC architecture and Von Neumann architecture, where as microcontroller used Harvard and RISC architecture most probably. But there are some microcontroller uses CISC architecture like 8051. But popularly microprocessor uses CISC architecture as our desktop computer (x86 architecture). Microprocessor has ROM, RAM, secondary storage memory I/O peripherals, timers; counters etc are placed on a board and connected through buses where as in the microcontroller all these peripherals are combined in a single integrated circuit (IC). ٨
The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt vectors, DOS BIOS, devices drivers, Command.com) and application programs. ٩ System Area: Holds the ROM BIOS, the video buffer area, and the BASIC language ROM. ١٠
Extended Memory: Memory above the 1M conventional memory found in AT compatible computers. Its size depends on the RAM installed on the motherboard, and is limited by the size of the processor s address bus. ١١ The 80x86 Registers ١٢
The Flag Register Z (zero): This flag is set to one if the result of the last arithmetic or logic instruction is zero. S (sign): This flag is set to one if the MSBit of the result of the last arithmetic or logic instruction is one, indicating a negative number. C (carry): This flag is set to one if the last arithmetic instruction gave a carry out or a borrow in. O (overflow): This flag is set to one if the result of the last arithmetic operation on signed numbers exceeded the capacity of the destination register. ١٣ 80x86 Modes of operation Protected mode Programs are given separate memory areas (segments) Programs are not allowed to access memory outside of their segments ١٤
Real address mode Environment of 8086 processor Direct access to system memory and hardware devices The operating system could crash ١٥ System management mode Provides an operating system for implementing power management and system security functions (computer manufacturers) ١٦
Program 01 // Program 01.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "conio.h" #include "iostream" unsigned int add(unsigned int n1, unsigned int n2) unsigned int result = n1+n2; return result; int _tmain(int argc, _TCHAR* argv[]) unsigned int x,y,z; printf("enter x :");scanf("%d",&x); printf("enter y :");scanf("%d",&y); z=add(x,y); printf("%d + %d = %d\n",x,y,z); printf("press any key to continue,..."); getch(); return 0; ١٧ Program 02 // Program 01.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "conio.h" #include "iostream" unsigned int add(unsigned int n1, unsigned int n2) _asm mov eax, n1 _asm mov edx, n2 _asm add eax, edx unsigned int result; _asm mov result,eax Return result; ١٨ int _tmain(int argc, _TCHAR* argv[]) unsigned int x,y,z; printf("enter x :");scanf("%d",&x); printf("enter y :");scanf("%d",&y); z=add(x,y); printf("%d + %d = %d\n",x,y,z); printf("press any key to continue,..."); getch(); return 0;
Program 03 // Program 01.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "stdio.h" #include "conio.h" #include "iostream" unsigned short int add(unsigned short int n1, unsigned short int n2) _asm mov ax,n1 _asm mov bx,n2 _asm add ax,bx Unsigned short int res; _asm mov res,ax return res ١٩ #include "stdafx.h" #include "stdio.h" #include "conio.h" #include "iostream" unsigned short int add(unsigned short int n1, unsigned short int n2) _asm mov ax,n1 _asm mov bx,n2 _asm add ax,bx unsigned short int res; _asm mov res,ax return res; unsigned short int sub(unsigned short int n1, unsigned short int n2) _asm mov ax,n1 _asm mov bx,n2 _asm sub ax,bx unsigned short int res; _asm mov res,ax return res; ٢٠ int _tmain(int argc, _TCHAR* argv[]) unsigned short int x,y,z; printf("enter x :");scanf("%d",&x); printf("enter y :");scanf("%d",&y); z=add(x,y); printf("%d + %d = %d\n",x,y,z); printf("press any key to continue,..."); getch(); return 0; unsigned short int mul(unsigned short int n1, unsigned short int n2) _asm mov ax,n1 _asm mov dx,n2 Program 04 _asm mul dx unsigned short int res; _asm mov res,ax return res; int _tmain(int argc, _TCHAR* argv[]) unsigned short int x,y,z; printf("enter x :");scanf("%d",&x); printf("enter y :");scanf("%d",&y); z=add(x,y); printf("%d + %d = %d\n",x,y,z); z=sub(x,y); printf("%d %d = %d\n",x,y,z); z=mul(x,y); printf("%d * %d = %d\n",x,y,z); printf("press any key to continue,..."); char ch = getch(); return 0;
Thanks,.. ٢١