You are on page 1of 32

Microprocessor Lab Manual

1. INTRODUCTION TO MASM
EDITOR An editor is a program, which allows you to create a file containing the assembly language statements for your program. As you type in your program, the editor stores the ASCII codes for the letters and numbers in successive RAM locations. hen you have typed in all of your programs, you then save the file on a floppy of hard dis!. "his file is called source file. "he ne#t step is to process the source file with an assembler. In the MASM assembler, you should give your source file name the e#tension, .asm. ASSEMBLER An assembler program is used to translate the assembly language mnemonics for instructions to the corresponding binary codes. hen you run the assembler, it reads the source file of your program the dis!, where you saved it after editing on the first pass through the source program the assembler determines the displacement of named data items, the offset of labels and puts this information in a symbol table. $n the second pass through the source program, the assembler produces the binary code for each instruction and inserts the offset etc that is calculated during the first pass. "he assembler generates two files on floppy or hard dis!. "he first file called the ob%ect file is given the e#tension. ob%. "he ob%ect file contains the binary codes for the instructions and information about the addresses of the instructions. "he second file generated by the assembler is called assembler list file. "he list file contains your assembly language statements, the binary codes for each instructions and the offset for each instruction. In MASM assembler, MASM source file name ASM is used to assemble the file. &dit source file name 'S" is used to view the list file, which is generated, when you assemble the file. LINKER A lin!er is a program used to %oin several ob%ect files into one large ob%ect file and convert to an exe file. "he lin!er produces a lin! file, which contains the binary codes for all the combined modules. "he lin!er however doesn(t assign absolute addresses to the program, it assigns is said to be relocatable because it can be put anywhere in memory to be run. In MASM, M'I)* source filename is used to lin! the file. DEBUGGER A debugger is a program which allows you to load your ob%ect code program into system memory, e#ecute the program and troubleshoot are debug it the debugger allows you to loo! at the contents of registers and memory locations after your program runs. It allows you to change the contents of register and memory locations after your program runs. It allows you to change the contents of register and memory locations and return the program. A debugger also allows you to set a brea! point at any point in the program. If you inset a brea!point the debugger will run the program up to the instruction where the brea!point is set and stop e#ecution. +ou can then

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

e#amine register and memory contents to see whether the results are correct at that point. In MASM, the filename is used to debug the file. DEBUGGER FUNCTIONS: .. ,ebugger allows to loo! at the contents of registers and memory locations. 2. e can e#tend /0bit register to .10bit register which the help of e#tended register option. 2. ,ebugger allows setting brea!points at any point with the program. 3. "he debugger will run the program up to the instruction where the brea!point is set and then stop e#ecution of program. At this point, we can e#amine registry and memory contents at that point. COMMANDS TO EXECUTE A GIVEN ALP. 1. ASSMEBLINIG '. LINKING ,. DEBUGGING : : : masm <f !e "ame.asm#$ <E"%e&$ ! "( <f !e "ame.)*+#$ <E"%e&$ -e*./ <f !e "ame.exe#$ <E"%e&$

DEBUGGER COMMANDS: DUMP: "o see the specified memory contents , memory location first address last address 4 hile displays the set of values stored in the specified range, which is given above5 E/: d 6.66 6.67 8cr9 ,isplay the contents of memory locations from .66 to .674including5. ENTER: "o enter data into the specified memory locations4s5. & memory location data data data data data :8cr9 E/: e .266 .6 26 26 36 :. &nters the above values starting from memory locations .266 to .262, by loading .6 into .266,26 into .26. and soon. GO: "o e#ecute the program ; address 8cr9< e#ecutes from current I- to the address specified ; first address last addresses 8cr9< e#ecutes a set of instructions specified between the given addresses. 0UIT: "o e#it from the debugger. = 8cr9 REGISTER: Shows the contents of Registers R register name &g< r a# Shows the contents of register. TRACE: "o trace the program instruction by instruction. " > 6.66 8cr9< traces only the current instruction. 4Instruction specified by I-5 " > 6.66 62 8cr9< "races instructions from .66 to .6., here the second argument specifies the number of instructions to be traced. UNASSEMBLE: "o unassembled the program.

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

Shows the opcodes along with the assembly language program. ? .66 8cr9< unassembled 22 instructions starting from .66th location. ? 6.66 6.6@ 8cr9< unassebles the lines from .66 to .63

'. ARIT1EMATIC OPERATIONS

'.a2. 34BIT ADDITION A m: "o write an assembly language program to add two /0bit numbers. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov al,62h mov bl,62h add al,bl hlt main endp end main Tes% -a%a: Input<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

$utput< Res.!%:

'.*2. 164BIT ADDITION A m: "o write an assembly language program to add two .10bit numbers.

A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov a#,.223h mov b#,322.h add a#,b# hlt main endp end main Tes% -a%a:

Input<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

$utput<

Res.!%:

'.72. 34BIT SUBTRACTION A m: "o write an assembly language program to substract two /0bit numbers. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov al,22h mov bl,22h sub al,bl hlt main endp end main

Tes% -a%a:

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

Input<

$utput<

Res.!%:

'.-2. 164BIT SUBSTRACTION A m: "o write an assembly language program to substract two .10bit numbers. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov a#,371Ah mov b#,.223h sub a#,b# hlt main endp end main Tes% -a%a:

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

Input<

$utput<

Res.!%:

'.e2. 34BIT MULTIPLICATION A m: "o write an assembly language program to multiply two /0bit numbers. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov al,//h mov bl,62h mul bl hlt main endp end main

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

Tes% -a%a: Input<

$utput<

Res.!%:

'.f2. 164BIT MULTIPLICATION A m: "o write an assembly language to multiply two .10bit numbers. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov a#,66..h mov b#,66..h mul b# hlt main endp

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

end main

Tes% -a%a:

Input<

$utput<

Res.!%:

'./2. 34BIT DIVISION A m: "o write an assembly language program to perform division on two /0bit numbers. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov al,3/h mov bl,.2h

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

div bl hlt main endp end main

Tes% -a%a: Input<

$utput<

Res.!%: '.82. 164BIT DIVISION A m: "o write an assembly language program to perform division on two .10bit numbers. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

mov a#,3333h mov b#,2222h div b# hlt main endp end main Tes% -a%a:

Input<

$utput<

Res.!%: ,. ASCII ARIT1EMATIC OPERATIONS ,.a2. ASCII ADDITION A m: "o write an assembly language program for ASCII addition. A55a&a%.s: MASM soft ware -C P&)/&am:

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

.model small .code main proc mov al,62h mov bl,62h add al,bl aaa add a#,2626h hlt main endp end main Tes% -a%a: Input<

$utput< Res.!%: ,.*2. ASCII SUBTRACTION A m: "o write an assembly language program for ASCII subtraction. A55a&a%.s: MASM soft ware -C P&)/&am: .model small

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

.code main proc mov al,6Ah mov bl,67h sub al,bl aas add a#,2626h hlt main endp end main Tes% -a%a: Input<

$utput<

Res.!%:

,.72. ASCII MULTIPLICATION A m: "o write an assembly language program for ASCII multiplication. A55a&a%.s: MASM soft ware -C P&)/&am:

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

.model small .code main proc mov al,6/h mov bl,62h mul bl aam add a#,2626h hlt main endp end main Tes% -a%a:

Input<

$utput< Res.!%:

,.-2. ASCII DIVISION A m: "o write an assembly language program for ASCII division. A55a&a%.s: MASM soft ware -C

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

P&)/&am: .model small .code main proc mov al,6/h mov bl,63h div bl aad add a#,2626h hlt main endp end main Tes% -a%a: Input<

$utput<

Res.!%:

9. PACKED BCD TO UNPACKED BCD : UNPACKED BCD TO PACKED BCD 9.a2. PACKED BCD TO UNPACKED BCD AIM: "o write an assembly language program to convert a pac!ed BC, number to unpac!ed BC, number.

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov al,71h mov dl,al and al,6f6h mov cl,63h ror al,cl mov bh,al and dl,6fh mov bl,dl mov a#,b# hlt main endp end main Tes% -a%a: Input< $utput< RESULT: 3.*2. UNPACKEDBCD TO PACKED BCD AIM: "o write an assembly language program to convert a ?npac!ed BC, number to pac!ed BC, number. APPARATUS:

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

MASM soft ware -C PROGRAM: .model small .code main proc mov a#,6761h mov cl,63h ror ah,cl mov bl,ah #or ah,ah add al,bl hlt main endp end main Tes% -a%a: Input<

$utput<

RESULT: ;. BCD %) ASCII CONVERSION

AIM: "o write an assembly language program to convert a BC, number

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

to its eCuivalent ASCII number. APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov al,71h mov dl,al and al,6f6h mov cl,63h ror al,cl mov bh,al and dl,6fh mov bl,dl mov a#,b# hlt main endp end main Tes% -a%a: Input< $utput< Res.!%: 6. DISPLA< A C1ARACTER A m:

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

"o write an assembly language program to display a character DE(. A55a&a%.s: MASM soft ware -C P&)/&am: data segment char db FEF data ends code segment assume cs<code, ds<data start< mov a#,data mov ds,a# mov dl,char mov ah,62h int 2.h mov al,3ch int 2 code ends end start Tes% -a%a: Input<

$utput<

Res.!%: =. DISPLA< A STRING

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

A m: "o write an assembly language program to display a string. A55a&a%.s: MASM soft ware -C P&)/&am: assume cs<code, ds<data data segment str. db G*ES HG str2 db G M-IMC 'ABHG data ends code segment start< mov a#,data mov ds,a# mov d#,offset str. mov ah,6@h int 2.h mov d#,offset str2 mov ah,6@h int 2.h mov al,3ch int 2 code ends end start Tes% -a%a: Input< $utput< Res.!%:

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

3. LENGT1 OF T1E GIVEN STRING A m: "o write an Assembly 'anguage -rogram 4A'-5 to find length of given string. A55a&a%.s: MASM soft ware -C P&)/&am: assume cs<code, ds<data data segment str. db G*ESR College of &ngineeringfor womenHG strlen eCu 4H0str.5 data ends code segment start< mov a#, data mov ds, a# sub cl, cl mov bl, str. mov cl, strlen mov a#, cl hlt code ends end start Tes% -a%a: Input<

$utput<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

Res.!%: >. STRING COMPARISION A m: "o write an assembly language program for compare two strings. Note: If the two strings are same display the result FFh in AX register and if the two strings are different display the result 00h in AX register. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov c#,6667h mov si,3666h mov di,1666h cld rep cmpsb %J go mov al,66h %mp go. mov al,6ffh mov bl,al hlt main endp end main 1666< 166.< 1662< 1662< 1663<

go< go.<

Tes% -a%a: I"5.%: 3666< 366.< 3662< 3662< 3663<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

O.%5.%: AK> Res.!%: 1?.BUBBLESORTING 1?.a2. ASCENDING ORDER A m: "o write an assembly language program for bubble sorting in asending order. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov cl,67h go< mov dl,63h mov si,3666h go.< mov al,LsiM inc si cmp al,LsiM %c go2 #chg al,LsiM dec si mov LsiM,al inc si go2< dec dl %nJ go. dec cl %nJ go hlt main endp end main Tes% -a%a: I"5.%: 3666< 366.< O.%5.%: 3666< 366.<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

3662< 3662< 3663< Res.!%: 1?.*2. DECENDING ORDER A m:

3662< 3662< 3663<

"o write an assembly language program for bubble sorting in decending order. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov cl,67h mov dl,63h mov si,3666h mov al,LsiM inc si cmp al,LsiM %nc go2 #chg al,LsiM dec si mov LsiM,al inc si dec dl %nJ go. dec cl %nJ go hlt main endp end main O.%5.%: 3666<

go< go.<

go2<

Tes% -a%a: I"5.%: 3666<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

366.< 3662< 3662< 3663< Res.!%:

366.< 3662< 3662< 3663<

11. MOVE A BLOCK A m: "o write an assembly language program for transfer a bloc! data. A55a&a%.s: MASM soft ware -C P&)/&am: .model small .code main proc mov cl,67h mov si,3666h mov di,1666h mov al,LsiM movLdiM,al inc si inc di dec cl %nJ up hlt main endp end main

up<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

Tes% -a%a: I"5.%: 3666< 366.< 3662< 3662< 3663< Res.!%:

O.%5.%:

1666< 166.< 1662< 1662< 1663<

1'.FACTORIAL OF A GIVEN NUMBER USING RECURSIVE NON4RECURSIVE MET1OD 1'.a2. RECURSIVE MET1OD AIM: "o write an assembly language program for factorial of a given number using recursive method. APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov al,67h mov bl,al dec bl call fact int 62 fact< mul bl dec b# %J down call fact down<ret main endp

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

end main Tes% -a%a: Input<

$utput< Res.!%:

1'.*2. NON4RECURSIVE MET1OD AIM: "o write an assembly language program for factorial of a given number using non0recursive method. APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov al,67h mov cl,67h mul cl dec cl %nJ up int 62 main endp end main

up<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

Tes% -a%a: Input<

$utput<

Res.!%:

1,. C1ECK @1ET1ER A GIVEN 164BIT NUMBER IS EVEN OR ODD

AIM: "o write a program to chec! whether a given .10bit number is even or odd. Note: 16-Bit num er should e gi!en at AX register" and result will e a!aila le at a##umulator$AX%. If the num er is e!en" store FFFFh at AX" and if it is odd" store 1111h at AX register. APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov c#,6666h mov a#,3333h mov b#,6662h div b# cmp d#,c# %e even mov a#,....h %mp down mov a#,6ffffh

even<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

down<

hlt main endp end main

Tes% -a%a: Input<

$utput< Res.!%:
19. DISPLA< T1E NUMBERS FROM ? TO > ON T1E SCREEN

AIM: "o write a program to display the numbers from 6 to @ on the screen. APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov a#, 6666h mov c#, 66.6h mov dl, F6F bac!< mov ah,62h int 2.h inc dl loop bac! mov ah, 3ch int 2.h

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

hlt main endp end main Tes% -a%a: Input<

$utput< Res.!%:

1;. DISPLA< ALP1ABETS FROM AaB TO ACB ON T1E SCREEN

AIM: "o write a program display alphabets from Da( to DJ( on the screen. APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov a#, 6666h mov c#, 66.ah mov dl, FaF bac!< mov ah,62h int 2.h inc dl loop bac! mov ah, 3ch

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

int 2.h hlt main endp end main Tes% -a%a: Input<

$utput< Res.!%:

16. PRINT SPECIAL C1ARACTERS ON T1E SCREEN USING DOSDBIOS INTERRUPT PROGRAMMING

AIM: "o write a program to print special characters on the screen using dosNbios interrupt programming. APPARATUS: MASM soft ware -C PROGRAM: .model small .code main proc mov a#, 6666h mov c#, 666Ah mov dl, F<F mov ah, 62h int 2.h

bac!<

Dr KVSR college of Engineering for women


&C& ,&-"

Microprocessor Lab Manual

inc dl mov ah, 3ch int 2.h hlt main endp end main Tes% -a%a: Input<

$utput< Res.!%:

Dr KVSR college of Engineering for women


&C& ,&-"

You might also like