0% found this document useful (0 votes)
11 views

Lecture 6 Assembly Language Programming - Introduction

Uploaded by

odero4029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Lecture 6 Assembly Language Programming - Introduction

Uploaded by

odero4029
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Microprocessors (0630371)

Fall 2010/2011 – Lecture Notes # 6

Assembly Language Programming -Introduction


Outline of the Lecture

 Example: adds and subtracts integers.


 Assembly language programs structure.
 Defining Data (Data Types).

Example: adds and subtracts integers

TITLE Add and Subtract (AddSub.asm)


; This program adds and subtracts 32-bit integers.
INCLUDE Irvine32.inc
.code
main PROC
mov eax,10000h ; EAX = 10000h
add eax,40000h ; EAX = 50000h
sub eax,20000h ; EAX = 30000h
call DumpRegs ; display registers
exit
main ENDP
END main

 The TITLE directive marks the entire line as a comment. You can put anything you want on this
line.
 The INCLUDE directive copies necessary definitions and setup information from a text file
named Irvine32.inc, located in the assembler’s INCLUDE directory
 The .code directive marks the beginning of the code segment, where all executable statements in a
program are located.
 The PROC directive identifies the beginning of a procedure.
 The MOV instruction moves (copies) the integer 10000h to the EAX register.
 The ADD instruction adds 40000h to the EAX register.
 The SUB instruction subtracts 20000h from the EAX register.
 The CALL statement calls a procedure that displays the current values of the CPU registers.
 The exit statement (indirectly) calls a predefined MS-Windows function that halts the program.
 The ENDP directive marks the end of the main procedure
 The END main directive marks the last line of the program to be assembled.

Program Output
Assembly language programs structure

TITLE Program Template (Template.asm)


; Program Description:
; Author:
; Creation Date:
; Revisions:
; Date: Modified by:
INCLUDE Irvine32.inc
.data
; (insert variables here)
.code
main PROC
; (insert executable instructions here)
exit
main ENDP
; (insert additional procedures here)
END main

Defining Segments One important function of assembler directives is to define program sections, or
segments.
 The .DATA directive identifies the area of a program containing variables:
.data
 The .CODE directive identifies the area of a program containing instructions:
.code
 The .STACK directive identifies the area of a program holding the runtime stack, setting its size:
.stack 100h

Defining Data (Data Types)

Data Types Essential Characteristics:


 Size in bits: 8, 16, 32, 48, 64, and 80.
 Signed and Unsigned.
 Pointer.
 Integral or Floating-point.

Data Definition Statement


A data definition has the following syntax:

[name] directive initializer [,initializer]...

 Name The optional name assigned to a variable must conform to the rules for identifiers, When
you declare an integer variable by assigning a label to a data allocation directive, the assembler
allocates memory space for the integer. The variable’s name becomes a label for the memory
space.
 Directive The directive in a data definition statement can be BYTE, WORD, DWORD, SBYTE,
SWORD, or any of the types listed in the following table
 In addition, it can be any of the legacy data definition directives shown in the following table

 Initializer At least one initializer is required


red in a data definition, even if it is zero. Additional
initializers, if any, are separated by commas.
 For integer data types, initializer is an integer constant or expression matching the size of the
variable’s type, such as BYTE or WORD.
 The Initializers and their description
descriptions are in the following table:

Data Initialization
 You can initialize variables when you declare them with constants or expressions that evaluate to
constants. The assembler generates an error if you specify an initial value too large for the variable
type.
 A ? in place of an initializer indicates you do not require the assembler to initialize the variable.
The assembler allocates the space but does not write in it.
o Use ? for buffer areas or variables your program will initialize at run time.
 You can declare and initialize
itialize variables in one step with the data directives, as these examples
show.

You might also like