0% found this document useful (0 votes)
95 views12 pages

Introduction to MASM Assembly Programming

The document outlines an experiment introducing students to assembly language programming using the Microsoft Macro Assembler (MASM) and DOS Debugger. It details the steps involved in writing, assembling, linking, and executing assembly language programs, as well as the tools required for the process. Additionally, it provides examples of assembly code and debugging commands used during the programming process.

Uploaded by

srikalaarege04
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)
95 views12 pages

Introduction to MASM Assembly Programming

The document outlines an experiment introducing students to assembly language programming using the Microsoft Macro Assembler (MASM) and DOS Debugger. It details the steps involved in writing, assembling, linking, and executing assembly language programs, as well as the tools required for the process. Additionally, it provides examples of assembly code and debugging commands used during the programming process.

Uploaded by

srikalaarege04
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

NRI

INSTITUTE OF TECHNOLOGY
Reg. No.:..20NA0Y Page No. : ...........

Experiment-I Date ailnl22


Tntroduc tion to MASM
ntoduction
The afm of thís experíment fs to fnttoduu the student
to assembly lanquaqe programing and the use ot
the tools that he oill need throughout the lab
experiment_. This tist experiment let the Student use
the Dos Debugger and the MicrDSott Macro Ass e mbler
(MASM). aitbn9 Assemblíng ínking Execute up can
be done using MASM softuoare
bieetiues
1 Inttoduction to MícYOSOft- Turbo Assenblev (TASM)
Q- Gheneral sttucture of an assernbls lanquage prDgoarn
3: use of the Dos
Dos -e
be bugge: progtam.
Ouervfeo
în qeneral paogrammfng ot mieroprocessor usually takes
Severa! ferations betore the víght Sequne of machíne
Code insttuchong is ori [Link] prouss howevev is
facilftated wing a specfal poqam called an "Assenbler":
the Assembley allous the usey to orí te alphanumeríc
ínstructíons . The AEGernbler1in turDqenerates the desire d
machine fnshuetons fom the assernbly lanquaqe
instuctions . Pssembty lanquoge proqamminq Cons is ts
of the folloing steps:
NRI
INSTITUTE OF TECHNOLOGY
Reg. No. Page No. : . . . . . . . . . .

STEP PRODU Ces


SOurce ftle
eaiting
ASsemblfng objett 4ile
Linking Executable.
Results.
Executtng
This sottuoe used to wríte aa program (8086, proccssor
etc). The proqrams ane oitten using assernbly
tanguage fo edi tor then comnptle it' The comptl
converts assembly lanquage staternents Toto nachfnel|
Lonquage. Statenents for eros. Then exeute the
Compf led pogam. Th ere are different sottoases
devolped by difterent companies for astembly
Longuage proqramming They are
1- MAS M(MOsot Macro Assermbler) -
MICYOSsott conpany.
QtASM (Turbo ssembler)
Bore kond Company
ASsennbiing tbe Pogram8
sed to
The assembley is used
to conuertthe assembly
Inshuctions to machine codeft fs us
Languagt
immedlately after loting the Rssembly (anguage
Progam. The assemblev s tarts by checking the
each
Syntax or Valí df bs ot the stuctue of
Snstu CHon n the Sous Hle "tt any e r s are
found . the a ssemblev displays a e poit on these
NRI
INSTITUTE OF TECHNOLOGY
Reg. No. :. Page No.:....Q.....

eiYors along oi th bret explanatfon of their nature


HouweveY iF the þroqram does contain any erors
the assemble procducAs an object tile that has the
Same name at the onginal tle but oith the bbË'
-ex tension:
LinkIng the pogO
an
The o ker is used Con vert the object Hle to
of
executable file. The exeutable file is the Hnal set
machine Code fnstu ctions thah Can di cty be exeuted
than the
by the mico pD essDY Tt is the díHesent
Obre ct Rle Sn the sense that ib fs gelf-contained
and elocatable n object fle may eprcsen t one
Segment of a long progra Thfs seqment Canno t
operatG by ftselt and. must be în tegrated oith
other obsecb t les epresening the est oF the
Progam, in ordey to povduce the fnal self-Con taÉ pl
executable ffle
Exeutng the pogam!
The exe utabie con ains the machi nc lanquage
T6 corn be lo aded Pn the RAM and exe cuted by the
mícroproussor Sírn ply by typfng tom the bos prormp
the name ot the fle follouwed by the carriage Retusn
poduus an output
key ten er key)" I the prpgamcontol
on the Scae en o Sequen, ot sfgnals to
should be
Contol apiec of hard o arC. the efect
notfced almos b- 1nmedlakely, Houwever, ff the
Program manipulates data In m enoy, nothi ng ooud
tle
Seem o have happend as aa tesult ofereuHng
NRI
INSTITUTE OF TECHNOLOGY
Reg. No. Page No. :...4.

Hou Te ENTER TNTO MASM ERITOR!


Ly crck Star t' on thc desktop
Lythen Select Run:
Ly then 1tt show [Link] type comrnand CCMD)
ohfch enttrs you Thto DOS pnompt
L5 path setting ichange path tom c dviue to o
dve using c:\>0 and press entey path
Chanqes to o driue.
Ls rype cd ASM.
b:\> MASM>
Type edit and press enter, Then you ente into
MASN text editDY
D: \>MASM> elit
y Then enter to FIe andsetect NeL. Aod oame
ft and then torite the ALP fo this edítoY .
Atter that sare Th as trle namets then extt
tom the editor and qo to prompt Thentype
MASMA 4lename "ASM:
0:\>MASM>M SM filenarme"ASM
Ly Then Línk this ile usthg
D;\>MASM>uNk ilename-oBT on
C,MASM>LI NKeilename "oBT íe inke the
Proqram in assenbly orth Dos -
to ereate. exe cutable ftp.
D:\>MASM >de bug ile narne-EXE.
Then 1t dísplay On the scocen.
NRI
INSTITUTE OF TECHNOLOGY
Reg. No. : Page No.: .....

After that type 'e' display's the Yeqts teort conten


nd stan ting Step of the prqram

Debug commands:Assemble

Assemby the instt uctions


Assermble ata particular addyesS
C
Compare Cormpat tuoo memoytanges

Dunp DÍsplay contents ot memony


G Go Exeute the proqra m
uTrenty in mermony
T Thace
Trate a sYngle instiucton
seqment code
emds dah
db
06H O4H, H, C3
o6H H,O4oH, dh a
sgmenl ta da
de:data codde, Molthylds: e assume
Addriorn
softoave SM MA )
computer Dpersonal
Lequemead. Soflaoare
cofa ering by
re. MASM
hong addrton,
sub ad like
opevations
Atmothe Muthityte perfom
Drean
BYTE
MATIc RTHI
XPERIMET-31
NRI No. Page :.RkAD4| No. Reg.
ECHNOLOGY INSTITUTE
OF
NRI
INSTITUTE OF TECHNOLOGY
Reg. No. : ...... Page No.:.. .......

O4H, 0GH s tart: mov A x, data


addihon : a db oH , ds, Ax
Motayte b db bQH, 04 H, 66 H
sI, offset a
O2 O 4 06 mov 5I, offset b
O2 04 oG
DOV Bx, offset c
Nanual ca leulatio mov CL,o3 H

O2 H 04H
BAck: mov AL, lsI|
+O 2H +o 4H + 0GH
DL,lDI]
O4 H ADC AL, DL
mov CBx], AL
SI
DI
13x

Dec
INZ BACK

Code cnds
end s tart
ubhaction:a db CoH, SOH, 4b NRI
N oTB YTE b db 30H, 0H, lbH Reg. No. :...........
INSTITUTE OF TECHNOLOGY
Page No. :......

30 3o M ULTI3yTe
O7GA :O00O
4030 20 lo
30 uBTRACTIONO:
assUme cs: co oe, ds:data
N anual ce lculaton datadbsegnent
GOH So H GoH, S0 H,40H
-30 H b db 30H, Q0H, lo H
30H 30H
data
Code
segment
start : mov AX, data
ds, Ax
}noV sI, offset a
DI, ofsei b
Bx, offset
CL, 03 H
BACk ! moV
AL,ls1]
DL, CDI]
AL,DL
[Bx], AL
SI
DT
Outtplicatio: Rea. No.: ....................)
NRI
INSTITUTE OF TECHNOLOGY
Page No. : :.(L.

0 G O2
BACK
O76A :000o O2 04
cod ends
Manual Caleulator star t
MwLTIBYTÉ VULTIPLIcATIDNi
O2 H O4 H O6H assume cs: code, ds:data
data
Gx G: 36
1613c db
sgmend O H,o4 H, 0GH
b db O2 H, o4H, oGH

data ends
cods sgoment
etart mov Ax, data
Movds, AX
mév sI, offse t a

DI, 01fset b
BX, Ofse t c
CL, 03H

BACk! DoV AL,[s I]


ov DL, [DJ]
DL
8XJ, AL
NRI
INSTITUTE OF TECHNOLOGY
Reg. No. Page No. :...

SI

DI

JNZ BACk
1NT O3H
Codi cnds
end tay t
MuriByre Divis} o
GSsume CS: code, ds: data
data sec

b db 62 , 04H, DG H

Star t: mov Ax, data


mov de, Ax
mov s I, 04set
mov D1, o4fset b
mev BX, offset c
CL 03H
CLC
BA Ck ! AL,[sI]
ov
by
ftware
anel
fubkacon and addition
o avsthmatie multibyle ta auRe
£SULT'
tavt s nd e
eds Code
03H
BAck
|3X
SI
DlV
..9. No. Page No. Reg.
NRI *****e
OLOGY INSTITUTE
OF
NRI
INSTITUTE OF TECHNOLOGY
Reg. No. 2kA.4 iI Page No.:...20)

Facborial I
yxPERIMeNT- 5 Dateotaly
Sx 4 X 3 Xx

CL
Ax facACTORIAL A Gen
4 S

O 3
aoo pefoa factoria l a gion muma
MAS softioare.
6 2
eraRATUs eQUIREMENTS:
Personal compute
)OAM softare.
assuMe cs! code
Ade
AL,LL() AL: AL cL code ceguent
etayt OOV c , os
XOR Ax,AX
moV Al,o
.mUL CL

TNT
cod euds
end start
Resu
factorial of a given nummber ii Llnhid by uag
mAsm softoare.

Common questions

Powered by AI

Debugging is vital in assembly language development because it helps identify and rectify errors in low-level code that interact directly with hardware. Given assembly's complexity and its closeness to machine code, even minor syntax errors or logical flaws can lead to significant issues like crashes or incorrect program behavior. Debugging tools allow developers to step through the code, inspect register values, and monitor memory changes, ensuring the correct execution of instructions and the program's stability .

The use of the DOS debugger and MASM for programming illustrates the critical interaction between hardware and software in assembly language programming. Assembly language is closely tied to the hardware architecture, making tools like debuggers essential for examining memory and executing instructions step by step. This level of interaction is necessary to understand how the software directly translates to hardware operations, thereby identifying errors and optimizing performance .

The assembler produces an object file from the source code, which contains intermediate machine code that does not yet form a complete program. This object file must be linked with other object files to create an executable file. Unlike the object file, the executable file is a self-contained unit that includes all necessary machine instructions to be executed by the processor. The executable can be loaded into RAM and run independently, whereas the object file represents only a segment of code that requires integration with other parts .

Converting an assembly language source file into a runnable program involves several steps. First, the source file is written using an editor. The assembler then converts this source into an object file, checking for syntax errors. The object file is then linked to form an executable file, ensuring all program segments fit together properly. Each step is crucial: editing allows for creation, assembling ensures code correctness, and linking creates a runnable program by merging various code segments .

Executable files must be self-contained to ensure they can run independently of other code, containing all necessary instructions and resources. Linked object files achieve this by combining various code segments from object files into a singular, cohesive unit that includes all machine code and dependencies required for execution. This allows the executable file to operate as a standalone application, ready to be loaded into memory and executed by the microprocessor, without needing further file integrations .

Linking multiple object files is crucial in assembly language for creating a complete software application. This process integrates separate pieces of code, often developed in isolation for modularity and manageability, into a coherent whole. Each object file typically represents a different module or function of a program. Linking resolves references between these modules, ensuring successful interaction and enabling the application to function as a single, unified program. This step is vital for assembling complex systems, where different functionalities need seamless integration .

Assembly language programming closely mirrors the operations of a microprocessor at a low level by using mnemonics and instructions that directly correspond to the operations carried out by the CPU. It involves hardware-specific commands that dictate control over the processor's operations, which include managing registers, memory addresses, and I/O ports. This low-level access and precision demonstrate how software commands translate into hardware actions, making assembly language an essential tool for understanding microprocessor architecture .

Byte calculations in assembly language programming hold significance due to their precision and direct interaction with memory. Assembly allows programmers to manipulate data at the byte level, optimizing software for specific hardware configurations. This enables efficient use of resources by minimizing memory usage and enhancing processing speed. Such calculations allow for highly efficient algorithms directly managing CPU registers and memory addresses, crucial for performance-critical applications .

Mnemonics greatly enhance the readability and writing of assembly language programs by providing human-readable codes to represent machine instructions. Unlike binary code, which is complex and error-prone, mnemonics like MOV, ADD, and SUB allow programmers to understand and write code more intuitively, bridging the gap between human comprehension and machine language. This approach simplifies programming while maintaining control over hardware operations .

Assemblers like MASM (Microsoft Macro Assembler) and TASM (Turbo Assembler) are tools used to convert assembly language instructions into machine code. The assembler checks the syntax and structure of each instruction in the source file, and if no errors are found, it generates an object file. This object file is then linked to produce an executable file, which is a self-contained set of machine instructions that can be directly executed by the microprocessor .

You might also like