1 / 22

Assembly Language Lecture 3

Assembly Language Lecture 3. Lecture Outline Named Constants Registers in 8086 Instruction Types MOV, XCHG, LEA, ADD, SUB, INC, DEC, NEG. Named Constants - EQU (Equates). To assign a name to a constant, we can use the EQU pseudo-op. Syntax: name EQU constant Examples:

presta
Télécharger la présentation

Assembly Language Lecture 3

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Assembly Language Lecture 3

  2. Lecture Outline • Named Constants • Registers in 8086 • Instruction Types • MOV, XCHG, LEA, ADD, SUB, INC, DEC, NEG

  3. Named Constants - EQU (Equates) • To assign a name to a constant, we can use the EQU pseudo-op. • Syntax: • name EQU constant • Examples: • LF EQU 0AH • MOV DL,0AH = MOV DL,LF • PROMPT EQU 'Any Thing' • MSG DB 'Any Thing' = MSG DB PROMPT • Note: no memory is allocated for EQU names.

  4. Registers • Information inside the microprocessor is stored in registers. • The registers are classified according to the functions they perform • In general there are fourteen 16-bit registers: • Data registers: • There are four general data registers. • They hold data for an operation. • Address registers: • They are divided into segment, pointer, and index registers. • They hold the address of an instruction or data. • Status register: • It is called the FLAGS register. • It keeps the current status of the processor.

  5. AH BH CH DH AL BL CL DL Registers Data Registers AX BX CX DX Segment Registers CS DS SS ES Pointer and Index Registers SI DI SP BP IP FLAGS Register

  6. Data Registers: AX, BX, CX, DX • These four registers, in addition to being general-purpose registers, • also perform special functions. • The high and low bytes of these registers can be accessed separately. • Ex. The high byte of AX is called AH, and the low byte is called AL. • This arrangement gives us more registers to use when dealing • with byte-size data.

  7. Data Registers: AX, BX, CX, DX • AX (Accumulator Register) is the preferred register to use in arithmetic, logic, and data • transfer instructions • BX (Base Register) also serves as an address register. • CX (Count Register) Program loop constructions are facilitated by the use of CX, which • serves as a loop counter. • DX (Data Register) is used in multiplication and division.

  8. Address Registers - Segment Registers CS, DS, SS, ES • Address registers store addresses of instructions and data in memory. • These values are used by the processor to access memory locations. • In the 8086 processor (16-bit processor): • Memory is a collection of bytes, each memory byte has an • address, starting with 0. • The processor assigns a 20-bit physical address to its memory • locations thus it is possible to address 2 = 1,048,576 bytes • (one megabyte) of memory. • The bytes in memory have addresses 00000h to FFFFFh. 20

  9. Address Registers - Segment Registers CS, DS, SS, ES • To keep track of the various program segments, the 8086 is • equipped with four segments registers to hold segment numbers: • CS (Code Segment): contains the code segment number. • DS (Data segment): contains the data segment number. • SS (Stack Segment): contains the stack segment number. • ES (Extra Segment): is used if a program needs to access a • second data segment.

  10. Instruction Types • Data transfer instructions: • Between registers. • Between registers and memory. • Between registers and I/O devices. • Examples: move, exchange, push, pop, input, output. • Data manipulation instructions: • Arithmetic operations: add, subtract. • Logical operations: and, or. • Shift/Rotate: shift right, shift left. • Program control instructions: • Examples: jump, call, loop, test, compare.

  11. Address Registers - Pointer and Index Registers: SP, BP, SI, DI • SP (Stack Pointer) register is used in conjunction with SS for • accessing the stack segment. • BP (Base Pointer) register is used primarily to access data on the • stack. However, unlike SP, BP can be used to access data in the • other segments. • SI (Source Index) register is used to point to memory locations in • the data segment addressed by DS. By incrementing the contents • of SI, we can easily access consecutive memory locations. • DI (Destination Index) register performs the same functions as SI. • There is a class of instructions, called string operations, that use DI • to access memory locations addressed by ES.

  12. Address Registers - Instruction Pointer (IP) • IP is updated each time an instruction is executed so that it will point • to the next instruction. • Unlike other registers, the IP cannot be directly manipulated by an • instruction (i.e. The instruction cannot contain IP as its operand).

  13. Note: any register can be used except CS & IP Before After 0006 0008 AX AX 0008 0008 WORD1 WORD1 MOV Instruction • The MOV (move) instruction is used to: • Transfer data between Registers. • Transfer data between registers and memory locations. • Move a number directly into a register or memory location. • Syntax: • MOV destination, source • Example: • MOV AX, WORD1 • MOV AX, BX • MOV AX, 'A'

  14. Legal Combinations of operands for MOV Destination Operand General Segment Memory Source operand register register location Constant General register yes yes yes no Segment register yes no yes no Memory location yes yes no no Constant yes no yes no • Illegal: MOV WORD1, WORD2 • Legal: MOV AX, WORD2 • MOV WORD1, AX • Illegal: MOV DS, CS • Legal: MOV AX, CS • MOV DS, AX

  15. Before After 1A 00 05 00 AH AL AH AL 00 05 00 1A BH BL BH BL XCHG Instruction • The XCHG (exchange) operation is used to exchange the contents • of: • Two registers. • A register and a memory location. • Syntax: • XCHG destination, source • Example: • XCHG AH, BL • XCHG AX,WORD1

  16. Legal Combinations of operands for XCHG Destination Operand General Memory Source Operand register location General register yes yes Memory location yes no

  17. LEA Instruction • LEA (Load Effective Address) puts a copy of the source offset • address into the destination. • Syntax: • LEA destination, source • Where destination is a general register and source is a memory • location • Example: • MSG DB 41H, 42H, 43H • LEA DX, MSG • puts the offset address of the variable MSG into DX. Data Definition + Basic Instructions 17

  18. Before After Before After 0000 FFFF 01BC 01BC AX AX AX AX 0001 0001 0523 06DF DX DX WORD1 WORD1 ADD and SUB Instructions • The ADD (add) and SUB (subtract) instructions are used to: • Add/subtract the contents of: • Two registers. • A register and a memory location. • Add/subtract a number to/from a register or memory location. • Syntax: • ADD destination, source SUB destination, source • Examples: • ADD WORD1, AX SUB AX, DX

  19. Legal Combinations of operands for ADD & SUB Destination Operand General Memory Source Operand register location General register yes yes Memory location yes no Constant yes yes • Illegal: ADD BYTE1, BYTE2 • Legal: MOV AL, BYTE2 • ADD BYTE1, AL

  20. Before After Before After 0002 0003 FFFE FFFD WORD1 WORD1 BYTE1 BYTE1 INC and DEC Instructions • INC (increment) is used to add 1 to the contents of a register or • memory location. • DEC (decrement) is used to subtract 1 from a register or memory • location. • Syntax: • INC destination DEC destination • Examples: • INC WORD1 DEC BYTE1

  21. Before After 0002 FFFE BX BX NEG Instruction • NEG is used to negate the contents of the destination. • It does this by replacing the contents by its two’s complement. • Syntax: • NEG destination • Examples: • NEG BX Negative integers are stored using 2’s complement in the computer Example: Want to store -5 in memory 1’s complement= 11111010 +1 11111011

  22. Type Agreement of Operands • The operands of any two-operand instruction must be of the same • type (i.e. Both bytes or words). • Illegal: MOV AX, BYTE1 • However, the assembler will accept both of the following: • MOV AH, 'A' moves 41H into AH • MOV AX, 'A' moves 0041H into AX

More Related