Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Organization & Assembly Language

Similar presentations


Presentation on theme: "Computer Organization & Assembly Language"— Presentation transcript:

1 Computer Organization & Assembly Language
University of Sargodha, Lahore Campus Prepared by Ali Saeed

2 EQU Statment This statement is use to declare constant in assembly language Name EQU constant LF EQU 0AH We can use LF any where in the code instead of OAH E.g Mov AH, LF

3 Arrays in Assembly Language
In assembly array is just a sequence of memory bytes or words For example to define three bytes array B_array with initial values 10H, 20H, 30H we can write B_array DB 10H, 20H, 30H B_array is associated with first address B_array+1 with second and B_array+2 with third element

4 Arrays in Assembly Language
In the same way we can define word W_array DW 1000, 40, 2020, 100 Initial word is associated with W_array, Next is associated with W_array+2, then W_array+4 then W_array+6

5 Arrays in Assembly Language
High and Low Byte of the word Sometime we need to refer High and Low bytes of the word like Word1 DW 1234H Low byte contain 34H High byte contain 12H Low byte have address Word1, and High byte have address Word1+1

6 Arrays in Assembly Language
Character String Array of ASCII codes can be initialized with a string of characters like: Letter DB ‘ABC’ Is equivalent to Letter DB 41H, 42H, 43H Letter DB 65, 66, 67

7 Arrays in Assembly Language
It is also possible to combine character and number in one defination MSG DB ‘HELLO’,0AH, 0DH, ‘$’ Is equivalent to MSG DB 48h, 45h, 4Ch, 4Ch, 4Fh, 0Ah, 0Dh, 24h

8 Arrays in Assembly Language
MONTHS DW 12 MONTHS DW 0CH MONTHS DW 0110B ;Declare 6 Bytes Array bytes  DB 10 DUP(?) ; Declare 10 uninitialized bytes starting at location bytes. Arr DD 100 DUP(0) ; Declare byte words starting at location arr, all initialized to 0

9 Array in Assembly Language
my_arr db 5, 2, 8, 9, 1, 7, 3, 0, 4, 6 To load the first element of the array into register al is like this: mov al, [my_arr] Accessing the second, the third, and the forth element is like this: mov al, [my_arr+1] mov bl, [my_arr+2] Mov [my_arr+3], cl

10 Translation of High level language to Assembly Language
Usually High level language instructions are first transferred into Assembly statements and than to machine language By using MOV, ADD, SUB, INC, DEC, and NEG we will transfer some High level instructions E.g. B=A MOV AX,A MOV B, AX

11 Examples A=5-A MOV AX, 5 SUB AX, A MOV A, AX OR NEG A ADD A,5
Student Exercise : A=B-2xA

12 Examples A=B-2xA Mov AX,B Sub AX,A Mov A,AX

13 Program Structure Machine Language programs consist of code, data and stack segment Each part occupies memory segment Each segment is translated into memory segment by Assembler

14 Memory Segment .Model Small (Code in One Segment, Data in One Segment)
Medium (Code in more than One Segment, Data in One Segment) Compact (Code in One Segment, Data in more than One Segment) Large (Code in more than One Segment, Data in more than One Segment, No array is more than 64K) Huge (Code in more than One Segment, Data in more than One Segment, Array may be more than 64K)

15 Data Segment .Data Data Segment contain all variable definitions
Constant definition are often made here Constant can also declare else where in the program Word1 DW 2 Word2 DW 5 MSG DB ‘This is Message’ Mask EQU B

16 Stack Segment Stack Segment is use to declare stack area in the memory
Stack area should be big enough to contain the stack at maximum size .Stack size Stack size is optional if not declared it 1K is set for stack area Stack 100H Stack 200H

17 Code Segment The code segment contain the program instructions
The declaration syntax is .Code name Name is optional, there is no need to write name in small program Inside the code segment instruction are organized in procedure

18 Code Segment Simplest procedure definition is Name PROC
; body of procedure Name ENDP .code MAIN PROC ; main procedure instructions MAIN ENDP ; other procedure go here

19 Example Program .model small .stack 100h .data .code main proc
mov mov ds,ax mov ah,01 int 21h mov dl,'x' mov ah,2 main endp end main

20 Thanks


Download ppt "Computer Organization & Assembly Language"

Similar presentations


Ads by Google