Computer Architecture Lab lecture 4 Assembly Language Types

Computer Architecture Lab lecture #4 Assembly Language

Types of Programming Languages The classifications of Programming languages: 1. High Level Languages (H. L. L) example: C/C++, VB, Java…etc 2. Low Level Languages (L. L. L) and its division to: -Machine Language: is the language that the hardware designers create and is it consists of sets of numbers (0 s and 1 s ) -Assembly Language.

Assembly Language is very low level-most of the code just moves values between the CPU registers and memory. Advantages of Assembly programs: 1. Take less memory and less time for run

Numbers in Assembly Language

Data Types of Assembly Language

Variables and units - To Define the Variables we use many keyword that mean: - In this course we use the following units:

Instructions in Assembly language instructions have the format: Instruction Label (optional): Marks the address of an instruction, must have a colon ; -Mnemonic: Identifies the operation (e. g. MOV, ADD, SUB. . etc). -Operand: Can be value, variable, register or memory location.

Instructions in Assembly clc ; No operands dec ax ; One operand Mov cx , dx ; Two operands -Any Text coming after a semicolon is a comment.

Operands in Assembly Language - There are 4 types of operands:

Registers: - are the fastest memories, located directly on the processor and manipulated directly by processor instructions.

Types of Registers - There are 4 main types of registers:

General Registers

Instruction categories Data Transfer Instructions: - Move Instruction Data Manipulation Instructions: -Arithmetic (Addition , Subtraction, Multiplication , Division).

MOV Instruction Copy Byte or Word From Source to Destination The Instruction’s Format: MOV Destination, Source -Destination: Can be Register or memory location. -Source: Can be Register or memory location or immediately value. -Example: MOV AX, 1354 -Note: Destination length must be >= Source length.

Examples of Mov Instruction Example: MOV AX, 152 F ; mov reg , immediate How does Apply the first instruction: -put the value (152 f) in the register AX , then the content of AX = 152 FH (display the value by hexadecimal). -Each digit stores in 4 bits as the following:

Important Notes 1. Can’t move an immediately value to segment register (CS, DS, ES, SS) but must put it in 16 -bit register as a general register (AX, BX, CX, DX) then move this value from general register to segment register. Example: MOV CS, 1234; mov 1234 into CS(illegal) To correct it: MOV AX, 1234 MOV

Important Notes 2. If the size of value (in source) bigger than the size of register (Destination) it well appear ERROR. Example: MOV AH , 58 FC; move 58 FC to AH (illegal) Because the size of AH 8 bit 3. If the size of value smaller than the size of register it well put 0’s in the remaining digits Example: MOV CX , 55 ; move 5500 into register CX (legal)

ADD Instruction Add 2 values (bytes or word or double word) and store the result in the destination. (destination = source + destination). -the registers must match in same size 16 or 8 bits. The Instruction’s Format: ADD Destination, Source -Destination: Can be Register or memory location. -Source: Can be Register or memory location or immediately value. -Example: ADD BX, 3245 ; bx=bx+324513

ADD Instruction Example Write an assembly language code in 2 different way to addition 2 numbers: num 1=12 A , num 2=1 E 21 -The first way: MOV AX, 12 A; move 12 a into Ax MOV BX, 1 E 21; move 1 E 21 into BX ADD AX, BX; add reg, reg means: ax=ax+bx -The second way: MOV AX, 12 A ; move 12 a into Ax ADD AX, 1 E 21; add reg, valu means: ax=ax+1 E 21
- Slides: 19