Jump to content

what are the mistakes in assembler program?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
mamandis

mamandis

    Newbie

  • Members
  • Pip
  • 1 posts
I am new in assembler, I am a student.
I gave an exercise to do a program:
write text with the keyboard (input) and in output all letters "a" should be changed to "*"

I tried to write something.. but it doesn't work..
program:


;program gavno
;------------------------------------
.Model small ;memory model
;64K for code and 64K for data

.Stack 100h

;----constants------------------------
StdOut = 1
CR = 0Dh
LF = 0Ah

;-----data-------------------------
.DATA
msgText DB "write a sentence:$"
msgEcho DB CR,LF,"you wrote:$"

inputBuf DB 255
DB 0
DB 255 DUP(?)

;------code----------------------------
.CODE
Strt:
mov ax,@data ;ds - data segment
mov ds,ax

mov dx,OFFSET msgText
call Write

mov ah,0Ah
mov dx,OFFSET inputBuf
int 21h ;reading from keyboard


repeat: ; until end of line

; find first symbol "a"
MOV DI,OFFSET "bufer"
MOV CX,"text_lenght"
MOV AL,'a'
REPNZ SCASB

;if end of the line, finish
JZ break_repeat

; if no, change the symbol and go forward
MOV [DI-1],'*'
JMP repeat

break_repeat:

mov dx,OFFSET msgEcho
call Write

mov dx,40h
mov bx,(StdOut)
mov cl,[inputBuf+1]
xor ch,ch
mov dx,OFFSET inputBuf+2
int 21h ;int 21,40 - output to file or hardware

mov ax,04C00h
int 21h ;int 21,4C - end of the program

;-----------------------------------------
Write PROC
push ax

mov ah,09h
int 21h ;int 21,09 - output to the screen

pop ax
ret
Write ENDP
;----------------------------------------------
END Strt

I don't know what to write in "bufer" and in "text_lenght" places..


please help me with this.. and if you see more mistakes I've done.. please fix it..

I would like to thank you in advance.. :)

#2
CFlat

CFlat

    Newbie

  • Members
  • Pip
  • 3 posts
I don't mean this in an offensive way, but you might want to comment your code a bit more thoroughly. You actually have a good start, but I don't recall off the top of my head what, for example, placing function 40H in AH does when you call interrupt 21H. If you don't know exactly step for step what you are doing in assembly, it is very easy to get lost, it is even easier for the people that help you to get lost. I would recommend a comment on almost every line. Then people are more able to help you :-)

#3
CFlat

CFlat

    Newbie

  • Members
  • Pip
  • 3 posts
BTW... I don't mean to sound like a pompous know it all either, honestly I haven't done all that much programming in Assembly. Quite awhile back I was pretty good at it though.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users