Lab Task For Assembly Language
Lab Task For Assembly Language
OBJECTIVE:
Theory:
Assembly Language: An assembly language is a low-level programming language for a
computer, or other programmable device, in which there is a very strong (generally one-to-one)
correspondence between the language and the architecture's machine code instructions. Each
assembly language is specific to a particular computer architecture, in contrast to most high-level
programming languages, which are generally portable across multiple architectures, but require
interpreting or compiling
Assembly language is converted into executable machine code by a utility program referred to as
an assembler; the conversion process is referred to as assembly, or assembling the code.
Assembly language consists of statements written with short mnemonics such as ADD, MOV,
SUB, and CALL. Assembly language has a one-to-one relationship with machine language: Each
assembly language instruction corresponds to a single machine-language instruction.
How Do C++ and Java Relate to Assembly Language?
High-level languages such as C++ and Java have a one-to-many relationship with assembly
language and machine language.
A single statement in C++ expands into multiple assembly language or machine instructions. We
can show how C++ statements expand into machine code. Most people cannot read raw machine
code, so we will use its closest relative, assembly language.
A language whose source programs can be compiled and run on a wide variety of computer
systems is said to be portable. A C++ program, for example, should compile and run on just
about any computer, unless it makes specific references to library functions that exist under a
single operating system. A major feature of the Java language is that compiled programs run on
nearly any computer system.
Assembly language is not portable because it is designed for a specific processor family. There
are a number of different assembly languages widely used today, each based on a processor
family. Some well-known processor families are Motorola 68x00, x86, SUN Sparc, Vax, and
IBM-370. The instructions in assembly language may directly match the computer’s architecture
or they may be translated during execution by a program inside the processor known as a
microcode interpreter
10110000 01100001
This binary computer code can be made more human-readable by expressing it in hexadecimal as
follows.
B0 61
Here, B0 means 'Move a copy of the following value into AL', and 61 is a hexadecimal
representation of the value 01100001, which is 97 in decimal. Intel assembly language provides
the mnemonic MOV (an abbreviation of move) for instructions such as this, so the machine code
above can be written as follows in assembly language, complete with an explanatory comment if
required, after the semicolon. This is much easier to read and to remember.
Syntax:
x86 assembly language has two main syntax branches: Intel syntax, originally used for
documentation of the x86 platform, and AT&T syntax.[1] Intel syntax is dominant in the MS-DOS
and Windows world, and AT&T syntax is dominant in the Unix world, since Unix was created at
AT&T Bell Labs. Many x86 assemblers use Intel syntax including MASM, TASM, NASM,
FASM and YASM.
A program consists of statement per line. Each statement is an instruction or assembler directive.
Statement syntax
Name operation operand(s) comment
Name field
Used for instruction labels, procedure names, and variable names
Assembler translates names into memory addresses
Names are 1-31 characters including letters, numbers and special characters ? . @
_ $ % . Names may not begin with a digit. If a period is used, it must be first
character. Names are Case insensitive
• COUNTER1
• @character
• SUM_OF_DIGITS
• $1000
• Done?
• .TEST
Examples of illegal names
• TWO WORDS
• 2abc
• A45.28
Operation field
Instruction
Assembler directive
An assembler directive is not translated into machine code. It tells the assembler to do
something.
Operand field
It Specifies data to be acted on. There can be Zero, one, or two operands.
Examples
• NOP
• INC AX
• ADD AX, 2
Comment field
A semicolon marks the beginning of a comment. A semicolon in beginning of a line
makes it all a comment line. Good programming practice dictates comment on every line
Examples
• MOV CX, 0 ; move 0 to CX
• Do not say something obvious
• MOV CX, 0 ; CX counts terms, initially 0
• Put instruction in context of program
• ; initialize registers
Applications:
Procedure:
Start Emu8086 by selecting its icon. Write
Program 01:
org 100h
; 5 +10 = 15 (decimal) or
hex=0Fhorbin=00001111b
add al, bl
ret
Register Value
AX
BX
CS
IP
Program 02:
org 100h
mov al, 5 ; al = 5
add al, -3 ; al = 2
ret
Register Value
AX
BX
CS
IP
Program 03:
Org 100h
mov bl, 5 ; bl = 5
add bl, -3 ; bl = 2
ret
Register Value
AX
BX
CS
IP
Program 04:
Org 100h
mov al, 5
sub al, 1 ; al = 4
ret
Register Value
AX
BX
CS
IP
Program 05:
Org 100h
mov al, 7
mov bl, 4
sub al,bl ret
Register Value
AX
BX
CS
IP