Req. For Assembly Language

Cards (22)

  • Assembly Language Features
    • Program comments
    • Reserved words
    • Identifiers
    • Statements
    • Directives
  • Program comments
    The comment field of a statement is used by the programmer to say something about what the statement does. A semicolon marks the beginning of this field, and the assembler ignores anything typed after the semicolon. Good programming practice dictates a comment on almost every line.
  • It is almost impossible to understand an assembly language program without comments
  • Comments are used to put the instruction into the context of the program
  • Reserved words

    • Instructions, such as MOV and ADD
    • Directives, such as END that used to provide information to the assembler
    • Operators
    • Predefined symbols, such as @Data, which return information to your program during the assembly
  • Identifiers
    • Name refers to the address of a data item
    • Label refers to the address of an instruction, procedure, or segment
  • Identifiers
    • Can be from 1 to 31 characters long (not case sensitive)
    • May consist of letters, digits, and the special characters ? . @ _ $ %
    • Names may not begin with a digit
    • If a dot is used, it must be the first character
  • Embedded blanks are not allowed in identifiers
  • YOU&ME is an example of an identifier containing an illegal character
  • Statements
    • Both instructions and directives have up to four fields: [identifier] operation [operand(s)] [comment]
    • At least one blank or tab character must separate the fields
    • The fields do not have to be aligned in a particular column, but they must appear in the above order
  • Directives
    • SEGMENT Directive: Data Segment, Stack segment, Code Segment
    • END Directive: ENDP directive ends a procedure, END directive ends the entire program and appears as the last statement
  • Program Structure - Memory Models
    • The size of code and data a program can have is determined by specifying a memory model using the .MODEL directive
    • SMALL: code in 1 segment, data in 1 segment
    • MEDIUM: code > 1 segment, data in 1 segment
    • COMPACT: code in 1 segment, data > 1 segment
    • LARGE: code > 1 segment, data > 1 segment, no array larger than 64k bytes
    • HUGE: code > 1 segment, data > 1 segment, arrays may be larger than 64k bytes
  • The appropriate model is SMALL, unless there is a lot of code or data
  • The .MODEL directive should come before segment definitions
  • Program Structure - Stack Segment
    • The purpose of the stack segment declaration is to set aside a block of memory (the stack area) to store the stack
    • The stack area should be big enough to contain the stack at its maximum size
    • Syntax: .STACK size
  • Program Structure - Stack Segment
    • .STACK 100H ; sets aside 100H bytes for the stack area
  • A segment is 2^16 = 64k
  • Program Structure - Data Segment
    • The data segment contains all the variable definitions
    • Constant definitions are often made here as well
    • To declare a data segment, we use the directive .DATA, followed by variable and constant declarations
  • Program Structure - Code Segment
    • The code segment contains a program's instructions
    • Syntax: .CODE name ; where name is an optional name of segment
    • Inside a code segment, instructions are organized as procedures
  • Program Structure - Code Segment (Procedures)
    The simplest procedure definition is: name PROC ; name: is the name of the procedure. ; body of the procedure ; PROC & ENDP: are pseudo-ops that delineate the procedure name ENDP
  • There is no need for a name in a SMALL program, However, the assembler will generate an error
  • A General Form of a .SMALL model program
    • .MODEL SMALL
    • .STACK 100H
    • .DATA ; data definitions go here
    • .CODE MAIN PROC ; instructions go here MAIN ENDP ; other procedures go here
    • END MAIN