Understanding Variables in System Programming Lab

defined variable n.w
1 / 9
Embed
Share

Learn about different types of variables, their declaration syntax, naming conventions, and ways to define numeric and string variables in System Programming Lab. Explore how to read variables using offsets and specific registers.

  • System Programming
  • Variables
  • Memory Location
  • Syntax
  • Numeric

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. DEFINED VARIABLE System Programing Lab Second Year

  2. Introduction Variable is a memory location. Our compiler supports two types of variables: BYTE and WORD There are two types of the variables: Numeric variable & String variables Syntax for a variable declaration: Name Ahmed1 Val_2 Directive DB DW Value 02H 0123H

  3. Introduction Name Can be consist of letters, numbers, and symbols. Must start with letter. Must defer from instruction names. It s not important small or large letter because assembly isn t sensitive language . Directive Can be DB to define byte, or DW to define 2 bytes. Value Can be any numeric, or string value in any supported numbering system (hexadecimal, binary, octal, ASCII or decimal), or "?" symbol for variables that are not initialized.

  4. Numeric variable Variable can define numerical numbers in multiple forms: Constant: value in this type of variables can not be change. Variable Description Var1 EQU 02 H Define constant number 8 bit Var1 EQU 0123 H Define constant number 16 bit Variable: value in this type of variables can be change Variable Description Var1 DB 02 H Define 1 value 8 bit stored at one memory location Var2 DW 0234 H Define 1 value 16 bit stored at tow memory locations Var3 DB 01H, 02H, 03H, 04H Define 4 values each 8 bit (array) at 4 memory locations Var4 DW 0123H, 4567H, 89ABH Define 3 values each 16 bit (array) at 6 memory locations Var7 DB 6DUP (01H) Define an array (6 ML) using DUP instruction Var8 DB 3DUP (01H,02H) Define an array (6 ML) using DUP instruction

  5. String variables String variables can be one or multiple letters Variable Description Define 1 ASCII Code at 1 memory locations Var5 DB A Define 5 ASCII Codes (array) at 5 memory locations Var6 DB AHMED Var7 DB A , H , M , E , D Define 5 ASCII Codes (array) at 5 memory locations DUP an instruction duplicate the value between brackets n times based on the number written before it. Variable Result Var5 DB 4DUP (02H) N=4 , Var5 = 02H, 02H, 02H, 02H Var5 DW 4DUP (0123H) N=4 , Var5 = 0123H, 0123H, 0123H, 0123H Var5 DB 4DUP (02H, 03H) N=4 , Var5 = 02H, 03H, 02H, 03H,02,03,02,03

  6. Reading Variables There are many ways to read variables: Offset : Store variable address into specific register. MOV BX, OFFSET Var1 LEA (load effective address) LEA BX, Var1 Direct : can use it if there is one value MOV AL, Var1 Program 1 MOV BX, offset Var1 MOV AL, [BX] HLT Var1 DB 01H Program 2 Program 3 LEA BX, Var1 MOV AL, [BX] HLT Var1 DB 01H MOV AL, Var1 HLT Var1 DB 01H

  7. Define Variables There are tow ways to define variables: At the beginning of program: .Data VAR1 DB 01H .code MOV BX, OFFSET VAR1 MOV AL, [BX] HLT At the end of program: MOV BX, OFFSET VAR1 MOV AL, [BX] HLT VAR1 DB 01H

  8. EXAMPLES Write a program to exchange the content of var1,var 2 .DATA Var1 DB 01H Var2 DB 02H MOV AX, 0100 MOV DS, AX MOV SI, OFFSET Var1 MOV DI, OFFSET Var2 MOV AL, [SI] MOV BL, [DI] MOV [SI], BL MOV [DI], AL HLT Var1 DB 01H Var2 DB 02H .CODE MOV AX, 0100H MOV DS, AX MOV SI, OFFSET Var1 MOV DI, OFFSET Var2 MOV AL, [SI] MOV BL, [DI] MOV [SI], BL MOV [DI], AL HLT

  9. EXAMPLES Write a program to transfer the content of var1 in data segment started at 2000H ,to var2 in stack segment started at 3000H .DATA Var1 DB 01H Var2 DB ? MOV AX, 2000H MOV DS, AX MOV SI, OFFSET Var1 MOV BL, [SI] MOV AX, 3000H MOV SS, AX MOV BP, OFFSET Var2 MOV [BP], BL HLT Var1 DB 01H Var2 DB ? .CODE MOV AX, 2000H MOV DS, AX MOV SI, OFFSET Var1 MOV BL, [SI] MOV AX, 3000H MOV SS, AX MOV BP, OFFSET Var2 MOV [BP], BL HLT

Related


More Related Content