Assembly language programming final examination site

Little knowledge

  1. 10 times of 2 is 1k

  2. When the address bus is 20 bits, the maximum memory is 1m. Reason: the 20th power of 2 1024k=1M

  3. A variable is the first address that the storage unit points to

Segment register offset address

Segment registerGeneral purpose register
DSBX, SI, DI or a 16 digit number
ESDI (for string instruction)
  • The CS code segment IP # CS can only be the source operand, not the destination operand MOV CS, AX; error

  • DS data segment BX, SI, DI or a 16 digit

  • SS stack segment SP or BP

  • ES additional segment

Segment base value (16 bits) shifts 4 bits to the left (i.e. 4-bit binary 0 is added at the end) = segment base address

EA (effective address) = base address + (index value X scale factor) + displacement

Physical address = EA + segment base address


  1. All the instructions that can be executed by a computer are called the instruction system or instruction set of the computer. The specific contents include instruction format, addressing mode and instruction type

The instruction system layer is the interface between hardware and software. The task of hardware is to execute instructions, and the program is embodied as instruction sequence

  1. 8086CPU is a 16 bit microprocessor. The internal and external data bus of CPU is 16 bits. One word (16 bits) data can be transmitted in a bus cycle, and the address bus is 20 bits, which can address 1MB main memory space
    The serial sequence cannot read the next instruction from main memory until one instruction is executed

The main memory capacity of 8086 / 8088 CPU is 1MB, and its main memory unit address is 20 bits, while the internal registers and data paths of CPU are 16 bits. How to expand the 16 bit address code to 20 bits?

Solution: divide 1MB main memory space into several segments, and the maximum length of each segment is 64KB. Accordingly, a register is set in the BIU to store the upper 16 bits of the 20 bit starting address, which is called the segment base value. The EU or instruction pointer IP provides the offset address (also known as offset) in the segment: the byte distance between a main memory unit and the segment base address of the segment

Address bus 20 bits 00000H-FFFFFH, byte storage, word storage, double word storage

Effective address: it is usually calculated by the CPU according to the addressing mode of the instruction or provided by the instruction pointer IP

Logical operation instruction

DEST; Destination operand SRC: source operand

  • AND logic AND instruction
    • Instruction format: AND DEST, SRC
    • 0 is 0, or 1 is 1
  • OR logic OR instruction
    • Instruction format: OR DEST, SRC
    • If one is 1, the result is 1
  • XOR logical XOR instruction
    • Instruction format: XOR DEST, SRC
    • 0 for the same and 1 for the different
  • NOT logical non instruction
    • Instruction format: NOT DEST
    • Reverse

Note: in the above operations, CF and OF will be set to 0 except NOT

Arithmetic instructions

  1. ADD addition

    • Instruction format: ADD DEST, SRC
    • The two numbers are added and the result is stored in DEST
  2. MOV transfer instruction

    • Instruction format: MOV DEST, SRC
    • Copy the operands in SRC to DEST
  3. XCHG exchange instruction

    • Instruction format: MOV DEST, SRC
    • Exchange the contents of the source and destination operands with each other
  4. Subtraction instruction

    1. SUB instruction

      • Instruction format: SUB DEST, SRC
      • Completes reducing the de source operand from the destination operand, that is: SEST = (SEST) - (SRC)
    2. DEC instruction

      • Instruction format: DEC DEST
      • Function: self minus one, DEST = (DEST) - 1
    3. CMP instruction

      • Instruction format: CMP DEST, SRC
      • The difference between the two operands does not retain the result, but only the changed flag bits: OF,SF,ZF,AF,PF, etc

Displacement command

  • SHL logic shift left
  • SHR logic shift right
  • Shift SAL arithmetic left
  • SAR arithmetic shift right
  • ROL cycle shift left
  • ROR cycle shift right
  • RCL with carry cycle shift left
  • RCR with carry cycle shift right

Instruction format:


Assembler case

Data segment definition format:

DATA SEGMENT ;Data segment


Stack segment definition format:

	DW 20H DUP (0)
CODE SEGMENT ;Code snippet
	ASSUME CS: CODE , DS:DATA,ES:EXTERA;Assume the storage location of each segment
START:   MOV AX, DATA			 ;Segment based refers to DS
         MOV DS,AX

		Instruction sequence
	 	MOV AH,4CH				;Call 4 CH Function, 4 CH Function number
            INT 21H			 	 ;Termination procedure

Assembly language statement format (case):

F = ( 10 ∗ ( X + Y ) − 3 ∗ ( Z − 1 ) ) / 2 F = (10 * (X + Y)-3 * (Z-1))/2 F=(10∗(X+Y)−3∗(Z−1))/2
The results are stored in FUN

DATA	SEGMENT;Set data segment
VARX	DW	123H;Define variables x

Set stack
               DW 20H DUP(0)

CODE SEGMENT;Set code snippet
            ASSUME CS: CODE, DS: DATA, SS: STACK1 ;Assume the storage location of each segment
STAET:      MOV AX, DATA			;Segment based refers to DS
            MOV DS,AX
            MOV AX,VARX				;Take the variable and copy it to AX in
            ADD AX,VARY				;AX = (X+Y)
            MOV BX,AX				;BX = AX = (X+Y)
            SAL AX,1				;AX = 2 * (X+Y)   Move the arithmetic left, equivalent to X2
            SAL AX,1				;AX = 4 * (X+Y)
            ADD AX,BX				;AX = 5 * (X+Y)
            SAL AX,1				;AX = 10 * (X+Y)
            MOV BX,VARZ				;Take variable Z
            DEC BX					;BX = BX-1 = Z-1
            MOV CX,BX				;CX = BX = Z-1
            SAL BX,1				;CX = 2 * (Z-1)
            ADD BX,CX				;BX = 3 * (Z-1)
            SUB AX,BX				;AX = 10 * (X+Y) - 2 * (Z-1)
            SAR AX,1				;ax = {10 * (X+Y) - 2 * (Z-1)}/2  Move the arithmetic right, equivalent to /2
            MOV FUN,AX				;Storage results
            MOV AH,4CH				;Call 4 CH Function, 4 CH Function number
            INT 21H					;Termination procedure

Tags: Interview

Posted on Sat, 20 Nov 2021 12:04:43 -0500 by dharprog