introduction to masm

29
Introduction to MASM .model: Model is an assembler directive. It is to inform the assembler that how many logical segments are used in the program. .model tiny: In this model all the memory is treated as single segment. .model small: In this model we have one code segment and one data segment. .model large: In this model we have two code segments and two data segments. .segment: Segment is an assembler directive. It is to tell the assembler that it is the starting of the logical segment. Ends: It is an assembler directive which informs the assembler that it is the end of the segment. Proc: Proc is used to call a subroutine. Assume: This makes the logical segment into physical segment. Masm: To convert the source code into object code and show errors. Syntax: masm filename.asm Link: To convert the object file into executable file. Syntax: link filename.obj Debug: To run the program. Syntax: debug filename.exe u: To unassembled the program.

Upload: gnanasambanthan-rajendran

Post on 02-Dec-2014

1.166 views

Category:

Documents


5 download

TRANSCRIPT

Page 1: Introduction to MASM

Introduction to MASM

.model: Model is an assembler directive. It is to inform the assembler that how many logical segments are used in the program.

.model tiny: In this model all the memory is treated as single segment.

.model small: In this model we have one code segment and one data segment.

.model large: In this model we have two code segments and two data segments.

.segment: Segment is an assembler directive. It is to tell the assembler that it is the starting of the logical segment.

Ends: It is an assembler directive which informs the assembler that it is the end of the segment.

Proc: Proc is used to call a subroutine.

Assume: This makes the logical segment into physical segment.

Masm: To convert the source code into object code and show errors.Syntax:  masm filename.asm

Link: To convert the object file into executable file.                Syntax:  link filename.obj

Debug: To run the program.                Syntax:  debug filename.exeu: To unassembled the program.

q: To quit the program.

g: go(complete execution).

t: trace the program(step by step execution).

eds: To enter the data into data segment.

dds: To display the data from data segment.

Posted by A Chandra Shaker Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz Labels: ALP, Assembly Language Programs, Macro Assembler Programs, MASM Programs, Microprocessors and Interfacing Lab, MPI Lab

Page 2: Introduction to MASM

Microprocessors and Interfacing Lab - 2

MASM Programs - 1

8-bit Additioncode:-          .model small          .code           main proc           mov al,02h           mov bl,05h           add al,bl           hlt           main endp           end main

output:-         ax=0007

8-bit Addition using address locationcode:-          .model small          .code           main proc           mov si,5000h           mov al,[si]           mov di,4000h           mov bl,[di]           add al,bl           hlt           main endp           end main

output:-         -eds:5000   5         -eds:4000   4

            ax=0009

8-bit Subtractioncode:-          .model small          .code           main proc           mov al,12h

Page 3: Introduction to MASM

           mov bl,21h           sub al,bl           hlt           main endp           end main

output:-         ax=00f1

8-bit Subtraction using address locationcode:-          .model small          .code           main proc           mov si,2145h           mov al,[si]           mov di,5432h           mov bl,[di]           add al,bl           hlt           main endp           end main

output:-         -eds:2145   10         -eds:5432    4

            ax=000c

8-bit Multiplicationcode:-          .model small          .code           main proc           mov al,12h           mov bl,15h           mul al,bl           hlt           main endp           end main

output:-         ax=017a

8-bit Divisioncode:-

Page 4: Introduction to MASM

          .model small          .code           main proc           mov al,10h           mov bl,02h           div bl           hlt           main endp           end main

output:-         ax=0008

16-bit Additioncode:-          .model small          .code           main proc           mov ax,0245h           mov bx,0436h           add ax,bx           hlt           main endp           end main

output:-         ax=067b

16-bit Subtractioncode:-          .model small          .code           main proc           mov ax,0245h           mov bx,0324h           sub ax,bx           hlt           main endp           end main

output:-         ax=ff21

16-bit Multiplicationcode:-          .model small

Page 5: Introduction to MASM

          .code           main proc           mov ax,0245h           mov bx,0123h           mul ax,bx           hlt           main endp           end main

output:-         ax=946f

16-bit Multiplication using address locationcode:-          .model small          .code           main proc           mov si,5112h           mov ax,[si]           mov di,1224h           mov bx,[di]           mul bx           hlt           main endp           end main

output:-         -eds:5112   12   21         -eds:1224    22  13

            ax=ba64

16-bit Divisioncode:-          .model small          .code           main proc           mov ax,0245h           mov bx,0124h           div bx           hlt           main endp           end main

output:-

Page 6: Introduction to MASM

         ax=0001

16-bit Division using address locationcode:-          .model small          .code           main proc           mov si,2432h           mov ax,[si]           mov di,5413h           mov bx,[di]           mul bx           hlt           main endp           end main

output:-         -eds:2432   44  24         -eds:5413   22  22

            ax=0001

Factorialcode:-          .model small          .code           main proc           mov cl,05h           mov al,cl           dec cl           go:mul cl           loop go           hlt           main endp           end main

output:-            ax=0078

Factorial using address locationcode:-          .model small          .code           main proc           mov si,2000h           mov cx,[si]

Page 7: Introduction to MASM

           mov ax,cx           dec cx           go:mul cx           loop go           hlt           main endp           end main

output:-         -eds:2000   05   00

         ax=0078

Posted by A Chandra Shaker Email This BlogThis! Share to Twitter Share to Facebook Share to Google Buzz Labels: ALP, Assembly Language Programs, Macro Assembler Programs, MASM Programs, Microprocessors and Interfacing Lab, MPI Lab

Microprocessors and Interfacing Lab - 3

MASM Programs - 2

Sum of Numberscode:-          .model small          .code           main proc           mov si,2000h           mov cl,04h           mov al,[si]           repeat:inc si           add al,[si]           loop repeat           hlt           main endp           end main

output:-         -eds:2000  08 06 0a 04 03

            ax=001f

Average of Numberscode:-

Page 8: Introduction to MASM

          .model small          .code           main proc           mov si,2000h           mov cl,04h           mov bl,05h           mov al,[si]           repeat:inc si           add al,[si]           loop repeat           div bl           hlt           main endp           end main

output:-         -eds:2000  02  04  05  03  06

            ax=0004

Sum of Squarescode:-          .model small          .code           main proc           mov si,3000h           mov cl,[si]           mov bx,00h           next:mov al,cl           mul cl           add bx,ax           dec cl           jnz next           hlt           main endp           end main

output:-         -eds:3000  04

            bx=001e  

Sum of Cubescode:-          .model small          .code

Page 9: Introduction to MASM

           main proc           mov si,3000h           mov cl,[si]           mov bx,00h           next:mov al,cl           mul cl           mul cl           add bx,ax           dec cl           jnz next           hlt           main endp           end main

output:-         -eds:3000  04

            bx=0064  

Ascending  Ordercode:-          .model small          .code           main proc           mov si,2000h           mov bl,05h           dec bl           go:mov cl,bl           repeat:mov al,[si]           inc si           cmp al,[si]           jb next           xchg al,[si]           dec si           mov [si],al           inc si           next:loop repeat           mov si,2000h           dec bl           jnz go           hlt           main endp           end main

output:-         -eds:2000  06 08 04 03 01

Page 10: Introduction to MASM

                     -dds:2000  01 03 04 06 08

Descending  Ordercode:-          .model small          .code           main proc           mov si,2000h           mov bl,05h           dec bl           go:mov cl,bl           repeat:mov al,[si]           inc si           cmp al,[si]           ja next           xchg al,[si]           dec si           mov [si],al           inc si           next:loop repeat           mov si,2000h           dec bl           jnz go           hlt           main endp           end main

output:-         -eds:2000  0f  03  0a  09  05                     -dds:2000  0f  0a 09  05  03

Maximum of Numberscode:-          .model small          .code           main proc           mov si,2000h           mov cl,05h           mov al,[si]           inc si           go:cmp al,[si]           jb next           jmp next1           next:mov al,[si]

Page 11: Introduction to MASM

           next1:inc si           loop go           hlt           main endp           end main

output:-         -eds:2000  23  45  12  56  32  67

            ax=0067

Minimum of Numberscode:-          .model small          .code           main proc           mov si,3000h           mov cl,04h           mov al,[si]           inc si           go:cmp al,[si]           ja next           jmp next1           next:mov al,[si]           next1:inc si           loop go           hlt           main endp           end main

output:-         -eds:3000  23  45  12  56  32 

            ax=0012

Sum of Numberscode:-          .model small          .code           main proc           mov si,2000h           mov cl,04h

Page 12: Introduction to MASM

           mov al,[si]           repeat:inc si           add al,[si]           loop repeat           hlt           main endp           end main

output:-         -eds:2000  08 06 0a 04 03

            ax=001f

Average of Numberscode:-          .model small          .code           main proc           mov si,2000h           mov cl,04h           mov bl,05h           mov al,[si]           repeat:inc si           add al,[si]           loop repeat           div bl           hlt           main endp           end main

output:-         -eds:2000  02  04  05  03  06

Page 13: Introduction to MASM

            ax=0004

Sum of Squarescode:-          .model small          .code           main proc           mov si,3000h           mov cl,[si]           mov bx,00h           next:mov al,cl           mul cl           add bx,ax           dec cl           jnz next           hlt           main endp           end main

output:-         -eds:3000  04

            bx=001e  

Sum of Cubescode:-          .model small          .code           main proc           mov si,3000h           mov cl,[si]           mov bx,00h           next:mov al,cl

Page 14: Introduction to MASM

           mul cl           mul cl           add bx,ax           dec cl           jnz next           hlt           main endp           end main

output:-         -eds:3000  04

            bx=0064  

Ascending   Order code:-          .model small          .code           main proc           mov si,2000h           mov bl,05h           dec bl           go:mov cl,bl           repeat:mov al,[si]           inc si           cmp al,[si]           jb next           xchg al,[si]           dec si           mov [si],al           inc si           next:loop repeat

Page 15: Introduction to MASM

           mov si,2000h           dec bl           jnz go           hlt           main endp           end main

output:-         -eds:2000  06 08 04 03 01                     -dds:2000  01 03 04 06 08

Descending   Order code:-          .model small          .code           main proc           mov si,2000h           mov bl,05h           dec bl           go:mov cl,bl           repeat:mov al,[si]           inc si           cmp al,[si]           ja next           xchg al,[si]           dec si           mov [si],al           inc si           next:loop repeat           mov si,2000h           dec bl

Page 16: Introduction to MASM

           jnz go           hlt           main endp           end main

output:-         -eds:2000  0f  03  0a  09  05                     -dds:2000  0f  0a 09  05  03

Maximum of Numberscode:-          .model small          .code           main proc           mov si,2000h           mov cl,05h           mov al,[si]           inc si           go:cmp al,[si]           jb next           jmp next1           next:mov al,[si]           next1:inc si           loop go           hlt           main endp           end main

output:-         -eds:2000  23  45  12  56  32  67

            ax=0067

Page 17: Introduction to MASM

Minimum of Numberscode:-          .model small          .code           main proc           mov si,3000h           mov cl,04h           mov al,[si]           inc si           go:cmp al,[si]           ja next           jmp next1           next:mov al,[si]           next1:inc si           loop go           hlt           main endp           end main

output:-         -eds:3000  23  45  12  56  32 

            ax=0012Logical AND

 code:-          .model small          .code           main proc           mov ax,3f0f h           mov bx,0008h           and ax,bx

Page 18: Introduction to MASM

           hlt           main endp           end main

output:-         ax=0008 

Logical ORcode:-          .model small          .code           main proc           mov ax,3F0Fh           mov bx,0008h           or ax,bx           hlt           main endp           end main

output:-         ax=3f0f 

Logical NOTcode:-          .model small          .code           main proc           mov ax,3F0Fh           not ax,bx           hlt           main endp           end main

Page 19: Introduction to MASM

output:-         ax=c0f0 

Logical XORcode:-          .model small          .code           main proc           mov ax,3F0Fh           mov bx,0008h           xor ax,bx           hlt           main endp           end main

output:-         ax=3f07 

Length of Stringcode:-          .model small          .stack  100h          .data           a  db 'chandra'           b dw $-a          .code           main proc           mov  ax,@data           mov ds,ax           mov  si,offset a           mov cx,b           int 21h

Page 20: Introduction to MASM

           main endp           end main

output:-            cx=0007

 Display a Stringcode:-          .model small          .stack  100h          .data           a  db 'abcd'           b dw $-a          .code           main proc           mov  ax,@data           mov ds,ax           mov  si,offset a           mov cx,b           repeat:mov dl,[si]           mov ah,02h           int 21h           inc si           loop repeat           mov ah,04h           int 21h           main endp           end main

output:-            abcd 

Page 21: Introduction to MASM

Reverse a Stringcode:-          .model small          .stack  100h          .data           a  db 'abcd'           b dw $-a          .code           main proc           mov  ax,@data           mov ds,ax           mov  si,offset a           mov cx,b           add si,cx           dec si           repeat:mov dl,[si]           mov ah,02h           int 21h           dec si           loop repeat           mov ah,04h           int 21h           main endp           end main

output:-            dcba

Palindrome Number code:-

Page 22: Introduction to MASM

          .model small          .code           main proc           mov si,4000h           mov cl,04h           mov ax,[si]           mov bx,[si]           xchg al,ah           ror al,cl           ror ah,cl           cmp ax,bx           jc next           mov dl,00h           jz exit           next:mov dl,01h           exit:hlt           main endp           end main

output:-          -eds:4000   12  21                     dx=0000

FAQ - 1

1. Define microprocessor?

A microprocessor is a multipurpose, programmable, clock-driven, register-based electronic  device that reads binary instructions from a storage device called memory accepts binary data as input and processes data according to instructions, and provides result as output.

2. Define microcomputer?

Page 23: Introduction to MASM

A computer  that  is  designed  using  a  microprocessor  as  its  CPU.  It includes microprocessor, memory, and I/O.

3. Define ROM?

A memory that stores binary information permanently. The information can be read from this memory but cannot be altered.

4. What is an ALU?

The group of circuits that provides timing and signals to all operation in the computer and controls data flow.

5. Define small-scale integration?

The process of designing a few circuits on a single chip. The term refers to the technology used to fabricate logic gates on a chip.

6. What is an instruction?

An instruction is a binary pattern entered through an input device in memory to command the microprocessor to perform specific function.

7. What are the four primary operations of a MPU?

a. Memory readb. Memory writec. I/O readd. I/O write

8. What do you mean by address bus?

The address bus is a group of 16 lines generally identified as A0   to A15. The address bus is unidirectional: bits flow from MPU to peripheral devices.

9. How many memory locations can be addressed by a microprocessor with 14 address lines?

The 8085 MPU with its 14-bit address is capable of addressing 214 =16,384 (ie) 16K memory locations.

Page 24: Introduction to MASM

10. Why is the data bus bi-directional?

 The data bus is bi-directional because the data flow in both directions between the MPU and memory and peripheral devices.