Saturday, 19 October 2013
Helps to write string manipulation programs using MASM 6.14
masm is very easy language if we understand every instruction used in the program and how these instructions executes. most of the instructions are same as intel 8086 microprocessor instructions other than 8086 instruction set is not a BIG thing. masm helps us to do string operations much easlier than in 8086 kit ( i don't know even they are possible in that kit).
//defining model and segments
MSG2 DB 'REVERSED STRING:$' //defining msg2.
//they stores in memory in DS.each string is terminated using a $ sign. its to make understand the compiler that string ended there.
this post is only a try to give my knowledge to readers. just try debugging one program and you fill understand what each instruction performs. even i don't know each and every word in this masm.
lets try to understand the following program
.MODEL SMALL
.STACK
.DATA
MSG1 DB 'ENTER A STRING:$'
MSG2 DB 'REVERSED STRING:$'
CRLF DB 13,10,'$'
ARR DB 100 DUP(?)
PUTS MACRO STR
MOV AH,09H
MOV DX,OFFSET STR
INT 21H
ENDM
.CODE
.STARTUP
PUTS CRLF
PUTS MSG1
MOV ARR,127
MOV AH,0AH
MOV DX,OFFSET ARR
INT 21H
MOV SI,1
MOV AL,ARR[SI]
MOV AH,0
MOV SI,AX
INC SI
PUTS CRLF
PUTS MSG2
PRINT:
MOV DL,ARR[SI]
MOV AH,02
INT 21H
DEC SI
CMP SI,1
JNZ PRINT
.EXIT
END
.STACK
.DATA
MSG1 DB 'ENTER A STRING:$'
MSG2 DB 'REVERSED STRING:$'
CRLF DB 13,10,'$'
ARR DB 100 DUP(?)
PUTS MACRO STR
MOV AH,09H
MOV DX,OFFSET STR
INT 21H
ENDM
.CODE
.STARTUP
PUTS CRLF
PUTS MSG1
MOV ARR,127
MOV AH,0AH
MOV DX,OFFSET ARR
INT 21H
MOV SI,1
MOV AL,ARR[SI]
MOV AH,0
MOV SI,AX
INC SI
PUTS CRLF
PUTS MSG2
PRINT:
MOV DL,ARR[SI]
MOV AH,02
INT 21H
DEC SI
CMP SI,1
JNZ PRINT
.EXIT
END
explanation
.MODEL SMALL
.STACK
.DATA
//defining model and segments
MSG1 DB 'ENTER A STRING:$ //defining msg1.
//they stores in memory in DS.each string is terminated using a $ sign. its to make understand the compiler that string ended there.
CRLF DB 13,10,'$' //crlf is a string which contains characters to go next line
ARR DB 100 DUP(?) // arr is an array of length that initialised to 00 in DS to store words from keyboard
after allocating these strings in memory,
msg1(000E-001D)
MSG2(001E-002E)
CRLF(002F-0031)
ARR(0032-0095)
PUTS MACRO STR //starts a macro. str is a variable
msg1(000E-001D)
MSG2(001E-002E)
CRLF(002F-0031)
ARR(0032-0095)
PUTS MACRO STR //starts a macro. str is a variable
MOV AH,09H //interrupt identification to print a string
MOV DX,OFFSET STR //offset address of required string is copied into dx
INT 21H // interrupted the processor to print the characters.
ENDM // end a macro
this macro is to print different strings. just like using functions.puts is a function name
int 21h is a interrupt that checks the AH and performs depending upon value of AH.
this macro is to print different strings. just like using functions.puts is a function name
int 21h is a interrupt that checks the AH and performs depending upon value of AH.
Subscribe to:
Comments (Atom)

