1 / 24

CEN 226 : Computer Organization & Assembly Language : CSC 225 (Lec#8)

CEN 226 : Computer Organization & Assembly Language : CSC 225 (Lec#8). By Dr. Syed Noman. Assembly Language Statements. Generally fall into two classes: Instructions - Executable Statements

Télécharger la présentation

CEN 226 : Computer Organization & Assembly Language : CSC 225 (Lec#8)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CEN 226: Computer Organization & Assembly Language :CSC 225(Lec#8) By Dr. Syed Noman

  2. Assembly LanguageStatements Generally fall into two classes: Instructions - Executable Statements Directives – statements that provide information to the assembler about how to generate executable code

  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

  4. Standard Assembler Directives

  5. Data Allocation Directives Char1 db ‘A’ hex db 41h Signed1 db -128 dec db 65 Signed2 db +127 bin db 01000001b Unsigned db 255 hex2 db 0A3h

  6. 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.

  7. Immediate Addressing Mode AL 00 Mov AL, 3CH AL 3C

  8. Register Addressing Mode AL 00 BL 4D Mov AL, BL AL 4D BL 4D

  9. Direct Addressing Mode Mov CL, [0020H] Memory (data) CL 78 Mov CX, [0020H] CX 5678 Mov ECX, [0020H] ECX 12345678 Little Endian Format – The “little” end of the number is stored first.

  10. Register Indirect Addressing Mode Mov SI, 0022H SI 0022 Mov CL, [SI] CL 34 In the 8086, only BX, BP, SI and DI may be used as memory pointers. Later processors don’t have this restriction.

  11. Base + Displacement MovBX, 0020H BX 0020 Mov AL, [BX +2] AL 34 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.

  12. Base + Index + Displacement (Useful when accessing individual elements in an record) Mov BX, 0020H ;BX points to record starting address BX 0020 Mov SI, 000CH ;SI points to record three (4 elements ;per record x 3 records = 000C) SI 000C Mov AL, [BX+SI+1] ;AL now has the data in element 1 of ;record #3 (assumes elements are 1 byte)

  13. Direct Addressing Direct-Offset Addressing .data Bytelist db 35h, 63h , 79h Wordlist dw 1234h, 5678h .code … Mov al, Bytelist ; al = 35 Mov al, Bytelist+1 ; al = 63 Movbx, Wordlist ; bx = 1234 Movbx, Wordlist+2 ; bx= 5678 Offset operator – returns the 16-bit address of the variable. Good for strings and arrays.

  14. Direct-Offset Addressing with Strings .data aString db “ASTRING” .code … Mov al, aString ; al = 41 Mov al, aString+1 ; al = 53 Mov al, aString+2 ; al = 54 Mov al, aString+3 ; al = 52

  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

  16. 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 . . .

  17. 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 movax,4c00h int 21h end

  18. 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(?) • Num1is 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

  19. BUFFERED KEYBOARD INPUT

  20. 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

  21. 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]

  22. 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

  23. 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

  24. 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.

More Related