Download presentation
Presentation is loading. Please wait.
Published byClyde Banks Modified over 9 years ago
2
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman
3
2 Assembly Language Statements Generally fall into two classes: Instructions - Executable Statements Directives – statements that provide information to the assembler about how to generate executable code
4
3 Names (Identifiers) Used to identify variables, constants, procedures, or code labels. ▫Max 247 characters ▫Not case-sensitive ▫First character can be a letter, ‘_’, ‘$’, ‘@’ ▫Subsequent characters may also be digits. ▫Cannot use an assembler reserved word. Should make identifier names descriptive and easy to understand
5
4 Standard Assembler Directives
6
5 Data Allocation Directives Char1 db ‘A’hex db 41h Signed1 db -128dec db 65 Signed2 db +127bin db 01000001b Unsigned db 255hex2 db 0A3h
7
Addressing Modes The 80x86 processors let you access memory in many different ways. The 80x86 memory addressing modes provide flexible access to memory, allowing you to easily access variables, arrays, records, pointers, and other complex data types. 6
8
7 AL 00 Immediate Addressing Mode Mov AL, 3CH AL 3C
9
8 Register Addressing Mode Mov AL, BL AL 00 BL4D AL4D BL4D
10
9 Direct Addressing Mode Mov CL, [0020H] Mov CX, [0020H] Memory (data) Little Endian Format – The “little” end of the number is stored first. CL 78 CX 5678 Mov ECX, [0020H] ECX 12345678
11
10 0022 Register Indirect Addressing Mode Mov CL, [SI] In the 8086, only BX, BP, SI and DI may be used as memory pointers. Later processors don’t have this restriction. Mov SI, 0022H CL 34 SI
12
11 BX 0020 Base + Displacement Mov AL, [BX +2] Useful when accessing individual elements in an array. Note that the array begins with element 0, element 2 corresponds to the third location in the array. The displacement corresponds to byte offset from the base, not element number in the array. Mov BX, 0020H AL 34
13
12 BX 0020 Base + Index + Displacement (Useful when accessing individual elements in an record) Mov BX, 0020H ;BX points to record starting address SI 000C Mov SI, 000CH ;SI points to record three (4 elements ;per record x 3 records = 000C) Mov AL, [BX+SI+1] ;AL now has the data in element 1 of ;record #3 (assumes elements are 1 byte)
14
13 Direct Addressing Direct-Offset Addressing Offset operator – returns the 16-bit address of the variable. Good for strings and arrays..data Bytelist db 35h, 63h, 79h Wordlist dw 1234h, 5678h.code … Moval, Bytelist; al = 35 Moval, Bytelist+1; al = 63 Movbx, Wordlist; bx = 1234 Movbx, Wordlist+2; bx = 5678
15
14 Direct-Offset Addressing with Strings.data aString db “ASTRING”.code … Moval, aString; al = 41 Moval, aString+1; al = 53 Moval, aString+2; al = 54 Moval, aString+3; al = 52
16
15 Base + Displacement ▫Mov AL, [BX + 4] Base + Index + Displacement ▫Mov AL, [BX+SI+3] Direct-Offset Addressing ▫Mov al, Bytelist+1 Immediate ▫Mov AL, 4CH Register ▫Mov AL, BL Direct ▫Mov AL, [20H] Register Indirect ▫Mov AL, [SI] Instruction Addressing Modes
17
Displaying A String Which May Contain A $-Character (Dos Function 40h).DATA... STRING_NAME DB ‘STRING THAT CONTAINS $ IS DISPLAYED’ STRINGLEN EQU $ - STRING_NAME ; $ refers to the current value in the location counter....CODE... MOV AH, 40H MOV BX, 01H ; file handle for the screen MOV CX, STRINGLEN ; string length MOV DX, OFFSET STRING_NAME INT 21H... 16
18
EP: Displaying $.model small.stack 100h.data $msg1 db " characters: $" @msg2 EQU $ - $msg1.code start: mov ax, @data mov ds, ax mov ah,40h mov bx,1 mov cx,@msg2 mov dx, offset $msg1 int 21h mov ax,4c00h int 21h end 17
19
BUFFERED KEYBOARD INPUT To read a string, a buffer (i.e., an array) must be defined to store that string. One way of defining the buffer is: BUFFER_NAME DB Num1, Num2 DUP(?) ▫Num1 is the maximum number of string characters to be read including the Carriage Return (0Dh), which is stored as the last character. ▫Num2 has a value which is one more than Num1; it is reserved to hold the actual length of the string (i.e., minus the Carriage Return character), the string, and the terminating Carriage Return character. Note: The maximum value for Num1 is FEh i.e., 254 18
20
BUFFERED KEYBOARD INPUT 19
21
BUFFERED KEYBOARD INPUT BUFFERED KEYBOARD INPUT (READING A STRING)(DOS FUNCTION 0AH): ANOTHER WAY OF DEFINING THE BUFFER To read a string of, say, maximum length 50 the buffer can be defined as: MAXLEN DB 51 ACTLEN DB ? BUFFER DB 51 DUP(?) To read a string into the buffer, we invoke DOS function 0AH as: MOV AH, 0AH MOV DX, OFFSET MAXLEN INT 21H 20
22
BUFFERED KEYBOARD INPUT Displaying a buffer, defined by using DOS function 40H: MOV AH, 40H MOV BX, 01H ; file handle for the screen MOV CH, 00H ; Initialize CX with the string length MOV CL, BUFFER[1] ; LEA DX, BUFFER[2] ; Output the string starting at byte 2 INT 21H ; Note: The statement: MOV DX, OFFSET BUFFER[2] is equivalent to: LEA DX, BUFFER[2] 21
23
BUFFERED KEYBOARD INPUT BUFFERED KEYBOARD INPUT (READING A STRING)(DOS FUNCTION 0AH): ANOTHER WAY OF DEFINING THE BUFFER To read a string of, say, maximum length 50 the buffer can be defined as: MAXLEN DB 51 ACTLEN DB ? BUFFER DB 51 DUP(?) ; becoz consecutive bytes To read a string into the buffer, we invoke DOS function 0AH as: MOV AH, 0AH MOV DX, OFFSET MAXLEN INT 21H 22
24
BUFFERED KEYBOARD INPUT Displaying a buffer, defined in by using DOS function 40H: MOV AH, 40H MOV BX, 01H ;file handle for the screen MOV CH, 00H ; Initialize CX with the string length MOV CL, ACTLEN LEA DX, BUFFER ; Display the buffer INT 21H 23
25
Practice program Write a program in assembly language that inputs and prints a string. ▫Using count stored in second byte ▫Using loop and stop when found enter. 24
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.