Microprocessor and Assembly Language Week-5 System Programming, BCS 6th, IBMS (2017)
High Speed Memory Registers CPU store data temporarily in these location CPU process, store and transfer data from one component to another with the help of registers More registers, High CPU Performance
Registers Size of registers depends on computer architecture Size of register is called Word Register is fastest (Nearer and inside CPU) Cache RAM HD is slowest System Programming, BCS 6th, IBMS (2017)
Registers Collection of Flip-Flops One Flip-Flop can store only one bit Flip-flop is a memory unit for single bit Early computers have 8-bits register then 16, 32 and now majority have 64 bits register System Programming, BCS 6th, IBMS (2017)
CPU Registers The general-purpose registers are primarily used for arithmetic and data movement. All of these registers can be further extended to 32 bits and 64 bits segment registers can not be extended which always occupy 16 bits. The extended register names begin with the letter E. For 64 bits R-prefix is added System Programming, BCS 6th, IBMS (2017)
32 bit General Purpose Registers System Programming, BCS 6th, IBMS (2017)
General-Purpose Registers (1) The AX, DX, CX, BX, BP, SP, DI, and SI registers are 16-bit general-purpose registers, used for temporary data storage. Since the processor accesses registers more quickly than it accesses memory, you can make your programs run faster System Programming, BCS 6th, IBMS (2017)
General-Purpose Registers (2) The processor can access four of the general registers AX, BX, CX, and DX These four registers are sometimes referred to as data registers. either as two 8-bit registers or as a single 16-bit register. E.g. System Programming, BCS 6th, IBMS (2017)
8 Bit High / 8 Bit Low Example: If AX contains the 16 bit number 1234h, than: AL contains 34h & AH contains 12h System Programming, BCS 6th, IBMS (2017)
General-Purpose Registers (3) AX: Accumulator Used for arithmetic operations purposes Some of operations such as MUL and DIV, requires one of operands be in the accumulator. Other operations ( ADD and SUB) can be applied to any of register, but are more efficient when working with the accumulator. System Programming, BCS 6th, IBMS (2017)
General-Purpose Registers (3) BX: Base Works as Pointer to base address Holds the address of variable Can also be used for arithmetic operations The only general purpose register used for indirect addressing Example: MOV [BX], AX CX: Count Count for loops, shifts OR Servers as loop counter DX: Data Used for Multiply, divide or I/O purpose It is a convenient place to store data System Programming, BCS 6th, IBMS (2017)
General-Purpose Registers (4) The remaining general-purpose registers can only be accessed using 32-bit or 16-bit names as shown in the following table: They are referred to as index/pointer registers System Programming, BCS 6th, IBMS (2017)
General-Purpose Registers These registers speed up processing of strings and arrays. SI: Source Index Pointer to the current character being read in a string instruction (LOD, MOV) Example: MOV [BX + SI], AX Used in string movement and points to the source string DI: Destination Index Pointer to the current character being written or compared in a string instruction Used in string movement and points to the destination string System Programming, BCS 6th, IBMS (2017)
General-Purpose Registers BP: Base Pointer Pointer to base address (stack) Some other place in the stack It is used for indirect addressing similar to BX SP: Stack Pointer Pointer to top of stack System Programming, BCS 6th, IBMS (2017)
Segment Registers (1) 16 bit Segment registers are CS, DS, SS, or ES. System Programming, BCS 6th, IBMS (2017)
Segment Registers (2) CS (Code Segment) Holds base locations for all executable instructions in a program Contains processor instructions and their immediate operands DS (Data Segment) Normally contains data allocated by the program SS (Stack Segment): Base location of the stack. ES(Extra Segment): Additional base locations for memory variables System Programming, BCS 6th, IBMS (2017)
IP (Instruction Pointer) It is also called program counter The IP register always contains the address of the next Instruction to be executed. Instructions that control program flow (such as calls, jumps, loops, and interrupts) automatically change the instruction pointer System Programming, BCS 6th, IBMS (2017)
Flag Register The FLAGS register is the status register in Intel x86 microprocessors that contains the current state of the processor. This register is 16 bits wide. Its successors, the EFLAGS and RFLAGS registers, are 32 bits and 64 bits wide, respectively. Most of flags are reserved for future use.
CPU Flags---(1) We use the values of CPU status flags to check the outcome of arithmetic operations The value of flag is either 0 or 1 1. Carry Flag The Carry flag indicates unsigned integer overflow. For example, if an instruction has an 8-bit destination operand but the instruction generates a result larger than 11111111 binary, the Carry flag is set.
Carry Flag-Example mov al,0ffh add al,1 CF is set to 1
CPU Flags---(2) 2. Zero flag The Zero flag indicates that an operation produce zero. For example, if an operand is subtracted from another of equal value, the Zero flag is set. Zf=1 if answer is zero..
Zero flag-example Org 100h mov cx,1 sub cx,1 Ret It sets ZF=1
CPU Flags---(3) 3. Sign flag The Sign flag indicates that an operation produced a negative result. If the most significant bit (MSB) of the destination operand is set, the Sign flag is set. SF=1 if MSB is set
Sign flag-example The example subtracts a larger integer (5) from a smaller one (4): Org 100h mov bl,4 sub bl,5 ; bl= -1, SF = 1
CPU Flags---(4) 4. Parity flag The Parity flag indicates whether or not an even number of 1 bits occurs. The even number of 1 s should be in the least significant byte of the destination operand. It occurs immediately after an arithmetic or boolean instruction has executed.
Parity flag-example Org 100h mov al,10001100b add al,00000010b ; AL = 10001110, PF = 1 sub al,10000000b ; AL = 00001110, PF = 0 RET
CPU Flags---(5) 5. Auxiliary Carry The Auxiliary Carry flag is set when a 1 bit carries out of position 3(starts from 0) in the least significant byte of the destination operand. The Auxiliary Carry (AC) flag indicates a carry or borrow out of bit 3 in the destination operand.
Auxiliary Carry-Example ORG 100h mov al,0fh add al,1 RET The sum (10h) or 16 contains a 1 in bit position 4 that was carried out of bit position 3.
CPU Flags---(6) 6. Overflow Flag: The Overflow flag is set when the result of a signed arithmetic operation overflows or underflows the destination operand. The largest possible integer signed byte value is 127; adding 1 to it causes overflow. Subtracting 1 from -128 causes underflow.
Overflow Flag-Example Org 100h mov al,+127 add al,1 ; OF = 1 mov bl,-128 sub bl,1 ; OF = 1
Data Types---(1) Data types, describes a set of values that can be assigned to variables of the given type. The essential characteristic of each type is its size in bits: 8, 16, 32, 48, 64 and so on. Emu8086 and MASM use different notations for defining data types.
Data Types (2) Masm supports: 1. BYTE(DB) : 8-bit unsigned integer. 2. SBYTE: 8-bit signed integer. S stands for signed 3. WORD(DW): 16-bit unsigned integer 4. SWORD: 16-bit signed integer 5. DWORD(DD): 32-bit unsigned integer. D stands for double 6. SDWORD: 32-bit signed integer. SD stands for signed double
Data Types (3) Emu8086 supports: DB: Define Byte DW: Define Word DD: Define Double word
1. BYTE(DB) The BYTE (define byte) and SBYTE (define signed byte) directives allocate storage for one or more unsigned or signed values. Each initializer must fit into 8 bits of storage. Example: value1 db 'A' ; in emu8086 value1 BYTE 'A' ; in masm
BYTE(DB) A question mark (?) initializer leaves the variable uninitialized value BYTE? Value db? o Multiple Initializers list BYTE 10,20,30,40
Example org 100h var db 49 ; var dw 49 can be used but with ax var1 db 55 mov al,var add al,var1 mov dl,al mov ah,2 int 21h Ret Result is h
Equate(Equ) Equ is used to define a constant Var equ 20 ;var=20 Example org 100h var equ 22 mov al,30 add al,var mov dl,al mov ah,6 int 21h ret
Taking Input from Keyboard org 100h ret mov ah,1 ; takes input int 21h ; execution add al,3 mov dl,al mov ah,6 int 21h
End
The End System Programming, BCS 6th, IBMS (2017)