Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Architecture CST 250

Similar presentations


Presentation on theme: "Computer Architecture CST 250"— Presentation transcript:

1 Computer Architecture CST 250
Assembly Language Prepared by:Omar Hirzallah

2 Contents Assembly Language Instruction Types
Introduction to Programming With Assembly

3 Assembly Language  An assembly language is a low-level programming language for a computer,microcontroller, or other programmable device, in which each statement corresponds to a single machine code instruction. Each assembly language is specific to a particular computer architecture, in contrast to most high-level programming languages, which are generally portable across multiple systems.

4 Instructions Syntax of assembly language Examples:
Operation [operand] , [operand/number] Examples: instruction Explanation mov ah, 25 Put 25 in ah register  dh=25 inc dx increase the value of dx by  dx=dx+1 add ax, bx add the contents of bx into ax. The result will be in ax register  ax=ax+bx sub cx, bx subtract the contents of bx from cx. The result will be in cx register  cx=cx-bx

5 Instructions Syntax of assembly language Examples:
Operation [operand] , [operand/number] Examples: instruction Explanation mov dh, b Put 5 in dh register  dh=5 add ax, b add the 15 into ax. The result will be in ax register  ax=ax+15

6 Instructions Examples: Decrease the value of dx by 1  dx=dx-1
Explanation dec dx Decrease the value of dx by 1  dx=dx-1 and ax, bx Do logical AND for ax with bx. The result will be in ax register  ax=ax && bx xor cx, bx Do logical XOR for bx with cx. The result will be in cx register  cx=cx ^ bx Mov ah, [x] Put the content of the memory variable x in ah  ah=x hlt Stop the processor

7 Instructions Examples: Shift all bits of dx (1 position) to the right
Explanation shr dx,1 Shift all bits of dx (1 position) to the right  dx=dx/2 shr dx, 2 Shift all bits of dx (2 position) to the right  dx=dx/4 shr dx, 3 Shift all bits of dx (3 position) to the right  dx=dx/8 shr dx, 4 Shift all bits of dx (4 position) to the right  dx=dx/16 shr dx, 5 Shift all bits of dx (5 position) to the right  dx=dx/32

8 Instructions Examples: Shift all bits of dx (1 position) to the left
Explanation shl dx,1 Shift all bits of dx (1 position) to the left  dx=dx * 2 shl dx, 2 Shift all bits of dx (2 position) to the left  dx=dx * 4 shl dx, 3 Shift all bits of dx (3 position) to the left  dx=dx * 8 shl dx, 4 Shift all bits of dx (4 position) to the left  dx=dx *16 shl dx, 5 Shift all bits of dx (5 position) to the left  dx=dx * 32

9 Instructions Examples: JUMP (Loops and if statements )
There are two : Conditional and Unconditional Instruction Explanation Cmp dx,1 je lable1 cmp means compare Je means jump if equal If(dx==1) Do the instruction in front of lable1 mov dx, 1 dec dx cmp dx, 0 je xyz add dx,5 xyz: inc dx .. If (dx != 0) { dx=dx-1; dx=dx+5 } dx=dx+1

10 ALU Operation Examples: JUMP (Loops and if statements ) Instruction
Cmp dx,1 je jne jl jle jg jge Instruction jmp Unconditional jump used at any time without CMP Instruction Conditional jump are used after CMP Instruction

11 Instruction types Data transfer instructions:
They move data from one register/memory location to another. 2. Arithmetic instructions: They perform arithmetical operations. 3. Logical instructions: They perform logical operations. 4. Control transfer instructions: They modify the program execution sequence. 5. Input/output (I/O) instructions: They transfer information between external peripherals and system components ( CPU/Memory) Processor control instructions: They control processor operation.

12 Example of : Arithmetic instruction
Add register1, register2 Flags ALU Operation [ A ]

13 Examples What will be the value of DX register after executing the following assembly code mov DX, 12 shl DX, 1 Add DX, 5 Mov CX, 40 Shr CX, 2 Add DX,CX

14 Examples How many times the following code block will execute
mov DX, 12 XYZ: Sub DX, 02 Add DX, 04 Mov CX, 34 And BX, 03 Xor DX, DX Cmp DX, 0 je XYZ

15 Examples Write the assembly instruction that clears bit # 1,2,4,7 of CL Register Solution clear means make the bit value is 0 Remember X . 1 = X X . 0 = 0 CL x and 1 CL x and CL, b

16 Examples Write the assembly instruction that sets bit # 1,2,4,7 of CL Register Solution Set means make the bit value is 1 Remember X + 1 = 1 X + 0 = X CL x OR 1 CL 1 x Or CL, b

17 Examples Write the assembly instruction that changes bit # 1,2,4,7 of CL Register Solution Change means if value is 0 make it 1 and if value is 1 make it 0 Remember X + 1 = X’ X + 0 = X CL x XOR 1 CL x xor CL, b


Download ppt "Computer Architecture CST 250"

Similar presentations


Ads by Google