0% found this document useful (0 votes)
47 views17 pages

Coal Lab 1 Output Screen Short

The document provides an introduction to assembly language and MASM. It discusses what assembly language is, the advantages of using assembly language, how an assembler works, and settings for MASM. It also covers the 8086 architecture including registers and instructions.

Uploaded by

Hamza Ramay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views17 pages

Coal Lab 1 Output Screen Short

The document provides an introduction to assembly language and MASM. It discusses what assembly language is, the advantages of using assembly language, how an assembler works, and settings for MASM. It also covers the 8086 architecture including registers and instructions.

Uploaded by

Hamza Ramay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Lab01 – Introduction to Assembly and MASM

Objective:

 Introduction to Assembly

 Comparison: Assembly Language vs C and Assembly Language vs Machine


Language

 Advantages of Assembly Language

 Working of Assembler

 MASM settings

◦ Pwb (Programmer’s Workbench)

◦ Command Prompt

What is Assembly Language?

 Low-level language

 Each instruction performs a much lower-level task compared to a


high-level language instruction

 One-to-one correspondence between assembly language and machine language


instructions

 For most assembly language instructions, there is a machine


language equivalent

 Assembler translates assembly language instructions to machine


language instructions

Directly influenced by the instruction set and architecture of the processor (CPU)

 Some example assembly language instructions:

inc result result++;

mov class_size,45 class_size=45;

NUML-Islamabad COAL-Lab Lab01


add marks,10 , marks+=10;

 Some points to note:

 Assembly language instructions are cryptic.

 Mnemonics are used for operations

 inc for increment, mov for move (i.e., copy)

 Assembly language instructions are low level

 Cannot write instructions such as mov marks, value

Most high-level language instructions need more than one assembly instruction

C- language Assembly Language

size = value; mov AX,value

mov size,AX

sum += x + y + z; mov AX,sum

add AX,x

add AX,y

add AX,z

mov sum,AX

Readability of assembly language instructions is much better than the machine language
instructions

Machine language instructions are a sequence of 1s and 0s

Assembly Language Machine Language (in Hex)

inc result FF060A00

mov class_size,45 C7060C002D00

and mask,128 80260E0080

NUML-Islamabad COAL-Lab Lab01


add marks,10 83060F000A

Why Program in Assembly Language?

 Two main reasons:

◦ Efficiency

 Space-efficiency

 Time-efficiency

◦ Accessibility to system hardware

 Space-efficiency

◦ Assembly code tends to be compact

 Time-efficiency

◦ Assembly language programs tend to run faster

 Only a well-written assembly language program runs faster

 Easy to write an assembly program that runs slower than its


high-level language equivalent

How does Assembler Work?

Assembler is such program that converts source-code programs from assembly language
to machine language. It generates

 Object file: it is a machine language translation of the program. The


object file may contain calls to sub-routines in an external library.

 Linker: it copies needed sub-routines from link library into object


file and produces executable program.

 Debugger: provides a way for programmer to trace execution of a


program and examine the contents of memory.

NUML-Islamabad COAL-Lab Lab01


 Listing File: contains generated machine code with line number

 Map File: addressing in memory that from where code segments


starts and where it ends and other addressing of the code.

DOSBOX 0.74

Using DOSBOX 0.74 for MASM611 on 64bit Machine

Installing DOSBOX

• Download and Install DOSBOX setup from SLATE, Installation is self


explanatory

o COAL LAB -> Resources –> Softwares -> DOSBOX

• Download “MASM for DOSBOX” from SLATE

o COAL LAB -> Resources –> Softwares -> 8086.rar

• Extract contents of 8086.rar in C drive.

Interface:

Drive mounting

NUML-Islamabad COAL-Lab Lab01


• DOSBox does not automatically make any drive (or a part of it) accessible to
the emulation.
• You have to make your directories available as drives in DOSBox by using the
"mount" command.
• For example, in Windows mount C \8086

• masm test.asm (this will create an object file)

NUML-Islamabad COAL-Lab Lab01


• link test.obj (this will create an executable)

• Test.exe (to run executable)

NUML-Islamabad COAL-Lab Lab01


Intel 8086 Architecture:

• The 8086 (also called iAPX 86) is a 16-bit microprocessor chip designed
by Intel between early 1976 and mid-1978, when it was released.
• It has a 20-bit address bus and a 16-bit data bus.
• As a programmer of 8086 you must become familiar with various registers.

Features of a Specific CPU:

NUML-Islamabad COAL-Lab Lab01


Intel 8086 (Registers):

• 8086 has total of Fourteen Registers accessible to programmer.


• Each register is 16 bits long i.e it can contain 16-bit binary number at max.
• General Purpose/Data Registers (AX, BX, CX, DX).
• Index/Pointer registers (SP, BP, SI, DI).
• Segment Registers (SS, DS, SS, ES).
• Control Registers (Flags, Instruction Pointer).

NUML-Islamabad COAL-Lab Lab01


• 8086 CPU has four 16-bit data registers

o AX - the accumulator register (divided into AH / AL).

o BX - the base address register (divided into BH / BL).

o CX - the count register (divided into CH / CL).

o DX - the data register (divided into DH / DL).

• These registers can be used in arithmetic or logic operations and as temporary


storage.

• The most significant byte of each register can be addressed directly (e.g AL is the
LS byte of AX, CH is MS byte of CX)

• A programmer determines the usage for each general purpose register.

• The main purpose of a register is to keep a number (variable).

• The size of the above registers is 16 bit, it's something


like: 0011000000111001b (in binary form), or 12345 in decimal (human) form.

NUML-Islamabad COAL-Lab Lab01


• 4 general purpose registers (AX, BX, CX, DX) are made of two separate 8 bit
registers

o For example if AX= 0011000000111001b, then AH=00110000b and


AL=00111001b.

o When you modify any of the 8 bit registers 16 bit register is also updated,
and vice-versa. The same is for other 3 registers, "H" is for high and "L" is
for low part.

• Registers are located inside the CPU, they are much faster than memory. accessing
a memory location requires the use of a system bus, so it takes much longer.

• Accessing data in a register usually takes no time. therefore, you should try to
keep variables in the registers for manipulation.

• Each data register has a special purpose too.

Register Special Purpose

AX Multiply/divide

BX Index Registers for MOVE

CX Count Register for String Operations

DX Port address for IN and OUT

Instruction:

NUML-Islamabad COAL-Lab Lab01


• Tells CPU what to do.

• Assembler converts the instruction in to machine code.

o Machine code is a sequence of bits can be read by the processor.

• Each instruction has

o Mnemonic (Required)

▪ Symbolic Code for Instructions or Commands to perform a


particular function

• mov, inc, add, sub, mul

o Operand (Optional/Depend on Instruction)

▪ On which operation is to be performed.

Type of Operands:

• Immediate
o A constant Integer of 8 or 16 bit.
• Register
o Name of register.
• Memory
o References to Memory Location.

Instruction Set:

• Data Transfer Instructions


• Logical Instructions
• Shift and Rotate Instructions
• Arithmetic Instructions
• Transfer Instructions
• Subroutine and Interrupt Instructions
• String Instructions
• Processor Control Instructions
• Data Transfer Instructions:

NUML-Islamabad COAL-Lab Lab01


Mnemonic Function

MOV Move byte or word to register or memory

IN, OUT Input byte or word from port, output word to port

LEA Load effective address

LDS, LES Load pointer using data segment, extra segment

PUSH, Push word onto stack, pop word off stack


POP

XCHG Exchange byte or word

XLAT Translate byte using look-up table

Data Transfer Instructions:

• MOV destination, source


o Transfer of data from source to destination.
o Source can be register, memory location or immediate data.
o Destination can be register or memory operand.
o Both source and registers cannot be memory location at the same time.
• Example
o MOV AX, 037AH;
o MOV AL, BL;
o MOV BX, [0301H];
• XCHG destination, source
o This register exchanges contents of source with destination.
o It cannot exchange two memory locations directly.
• Example
o XCHG BX, AX;
o XCHG [5000H], AX;
• What’s wrong..
o XCHG [2000H], [4000H];

NUML-Islamabad COAL-Lab Lab01


Logical Instructions:

Mnemonic Function

NOT Logical NOT of byte or word (one's complement)

AND Logical AND of byte or word

OR Logical OR of byte or word

XOR Logical exclusive-OR of byte or word

TEST Test byte or word (AND without storing)

• NOT operand
o Invert each bit of operand
o Example
o MOV AL, 00011011b
o NOT AL; (Value of AL will be 11100100)
• AND operand1, operand2
o Logical AND between all bits of two operands
o Example
• MOV AL, 110011000b
• AND AL, 001101110b
• OR operand1, operand2
o Logical OR between all bits of two operands
o Example
• MOV AL, 00001100b
• OR AL, 00110111b; (AL = 00111111)
• XOR operand1, operand2
o Logical XOR between all bits of two operands
o Example
• MOV AL, 11001100b
• XOR AL, 00000111b ; (AL = 11001011)

NUML-Islamabad COAL-Lab Lab01


Shift and Rotate Instruction:

Mnemonic Function

SHL, SHR Logical shift left, right byte or word, by 1 or CL

SAL, SAR Arithmetic shift left, right byte or word, by 1 or CL

ROL, ROR Rotate left, right byte or word, by 1 or CL

RCL, RCR Rotate left, right through carry byte or word, by 1 or CL

• SHL operand1, operand2


o Example
o MOV AL, 11100000b
o SHL AL, 1 ; AL = 11000000b
• SHR operand1, operand2
o Example
o MOV AL, 00000111b
o SHR AL, 1 ; AL = 00000011b
• ROL operand1, operand2
o shift all bits left, the bit that goes off is inserted to the right-most position.
o Example
o MOV AL, 1Ch ; AL = 10011100b
o ROL AL, 1 ; AL = 00111001b
• ROR operand1, operand2
o shift all bits right, the bit that goes off is is inserted to the left-most position
o Example
o MOV AL, 1Ch ; AL = 00011100b
o ROR AL, 1 ; AL = 00001110b

Arithmetic Instructions:

NUML-Islamabad COAL-Lab Lab01


Mnemonic Function

ADD, Add, subtract byte or word


SUB

ADC, SBB Add, subtract byte or word and carry (borrow)

INC, DEC Increment, decrement byte or word

NEG Negate byte or word (two's complement)

CMP Compare byte or word (subtract without storing)

MUL, DIV Multiply, divide byte or word (unsigned)

IMUL, Integer multiply, divide byte or word (signed)


IDIV

CBW, Convert byte to word, word to double word (useful before multiply/divide)
CWD

AAA, ASCII adjust for addition, subtraction, multiplication, division (ASCII


AAS,
codes 30-39)
AAM,

AAD

DAA, Decimal adjust for addition, subtraction (binary coded decimal numbers)
DAS

• ADD operand1, operand2


o Add contents of operand2 on operand1
o Example
• MOV AL, 5 ; AL = 5
• ADD AL, 3 ; AL = 8
• SUB operand1, operand2

NUML-Islamabad COAL-Lab Lab01


o SUB contents of operand2 on operand1
o Example
• MOV AL, 5 ; AL = 5
• SUB AL, 3 ; AL = 2
• INC operand1
o operand = operand + 1
o Example
o MOV AL, 228 ;
o INC AL ; AL = 229
• DEC operand1
o operand = operand - 1
o Example
o MOV AL, 255 ;
o DEC AL ; AL = 254
• MUL operand1
o Multiply operand1 with contents placed in register AX
o Example
o MOV AX, 200 ;
o MOV BL, 4
o MUL BL ;
• DIV operand1
o when operand is a byte: AL = AX / operand and AH = remainder
o when operand is a word: AX = (DX AX) / operand and DX = remainder
o Example
o MOV AX, 203;
o MOV BL, 4;
o DIV BL ; AL = 50 , AH = 3
• NEG operand1
o Invert all bits of the operand and Add 1 to inverted operand. 2’s
Complement
o Example
o MOV AL, 01100111 ;
o NEG AL ; AL = 10011001;

NUML-Islamabad COAL-Lab Lab01


Activity:

• MASM must be installed and configured by using either of methods discussed.


• Must have tested a code on your installed assembler.
• Number system revision.
• Understanding of Assembly language and Assembler.
• Understanding of 8086 Data/Special purpose registers and Instructions which
are discussed today.

NUML-Islamabad COAL-Lab Lab01

You might also like