Link to home
Start Free TrialLog in
Avatar of lewis_loo
lewis_loo

asked on

assembly (string)

Please show me the code which is  runable with the following criteria

code the program to input the string, character by character using pop and push, push it one by one in a variable, then pop one by one in another variable (so that it show the reverse of the first string) and have to consider the backspace

if I don't understand your code, can I have your email address so I can ask you if any problem
Avatar of Jan Louwerens
Jan Louwerens
Flag of United States of America image

Is this a school assignment?
Avatar of lewis_loo
lewis_loo

ASKER

No, I have doing it by using swaping but it's too long I think I should use push and pop. but I don't know how to implemented on it?

I can send you my source and if can please improve this source or change to push or pop I think it would better than doing swaping like this

TITLE reverse.asm
DOSSEG
..MODEL SMALL
..STACK 100h
..DATA
msg db "Enter a phrase (not more than 30 characters) : $"
errormsg db "Error, Please input not more than 30 characters$"


temp dw ?
total dw ?
TotalStrLen dw ?
char1 db ?
char2 db ?

NAMEPAR LABEL BYTE
MAXNLEN DB 31
NAMELEN DB ?
NAMEFLD DB 32 DUP(' '),'$'

..CODE

clrscr proc near
; mov ah,6
; mov al,0
; mov bh,7
; mov cx,0
; mov dh,24
; mov dl,79
; int 10h
 mov ah,0
 mov al,3
 int 10h
 ret
clrscr endp

prompt proc near
 mov dx,offset msg
 mov ah,9
 int 21h
 ret
prompt endp

input proc near
 mov ah,0Ah
 mov dx,offset NAMEPAR
 int 21h
 ret
input endp

reverse proc near
 mov bh,0
 mov bl,namelen
 sub bx,1
 mov temp,bx
 mov TotalStrLen,bx
 mov total,bx
 shr total,1

up:
 mov dl,namefld[bx]
 mov char1,dl

 mov bx,TotalStrLen
 sub bx,temp
 mov dl,namefld[bx]

 mov bx,temp
 mov namefld[bx],dl

 mov bx,TotalStrLen
 sub bx,temp
 mov dl,char1
 mov namefld[bx],dl

 dec temp
 mov bx,temp
 
 dec total
 cmp total,0
 jge up

 ret
reverse endp

moveto proc near
 mov ah,2
 int 10h
 ret
moveto endp

makecenter proc near
 mov dl,namelen
 shr dl,1
 neg dl
 add dl,40
 mov dh,12
 call moveto
 ret
makecenter endp

output proc near
 mov ah,9
 mov dx,offset namefld
 int 21h
 ret
output endp

readkey proc near
 mov ah,8
 int 21h
 ret
readkey endp
 
start:
 call clrscr
 mov ax,@data
 mov ds,ax
 call prompt
 call input
 call makecenter
 call reverse
 call output
 call readkey

 mov ah,4Ch
 int 21h
end start
No, I have doing it by using swaping but it's too long I think I should use push and pop. but I don't know how to implemented on it?

I can send you my source and if can please improve this source or change to push or pop I think it would better than doing swaping like this

TITLE reverse.asm
DOSSEG
..MODEL SMALL
..STACK 100h
..DATA
msg db "Enter a phrase (not more than 30 characters) : $"
errormsg db "Error, Please input not more than 30 characters$"


temp dw ?
total dw ?
TotalStrLen dw ?
char1 db ?
char2 db ?

NAMEPAR LABEL BYTE
MAXNLEN DB 31
NAMELEN DB ?
NAMEFLD DB 32 DUP(' '),'$'

..CODE

clrscr proc near
; mov ah,6
; mov al,0
; mov bh,7
; mov cx,0
; mov dh,24
; mov dl,79
; int 10h
 mov ah,0
 mov al,3
 int 10h
 ret
clrscr endp

prompt proc near
 mov dx,offset msg
 mov ah,9
 int 21h
 ret
prompt endp

input proc near
 mov ah,0Ah
 mov dx,offset NAMEPAR
 int 21h
 ret
input endp

reverse proc near
 mov bh,0
 mov bl,namelen
 sub bx,1
 mov temp,bx
 mov TotalStrLen,bx
 mov total,bx
 shr total,1

up:
 mov dl,namefld[bx]
 mov char1,dl

 mov bx,TotalStrLen
 sub bx,temp
 mov dl,namefld[bx]

 mov bx,temp
 mov namefld[bx],dl

 mov bx,TotalStrLen
 sub bx,temp
 mov dl,char1
 mov namefld[bx],dl

 dec temp
 mov bx,temp
 
 dec total
 cmp total,0
 jge up

 ret
reverse endp

moveto proc near
 mov ah,2
 int 10h
 ret
moveto endp

makecenter proc near
 mov dl,namelen
 shr dl,1
 neg dl
 add dl,40
 mov dh,12
 call moveto
 ret
makecenter endp

output proc near
 mov ah,9
 mov dx,offset namefld
 int 21h
 ret
output endp

readkey proc near
 mov ah,8
 int 21h
 ret
readkey endp
 
start:
 call clrscr
 mov ax,@data
 mov ds,ax
 call prompt
 call input
 call makecenter
 call reverse
 call output
 call readkey

 mov ah,4Ch
 int 21h
end start
ASKER CERTIFIED SOLUTION
Avatar of Rheingold
Rheingold

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What it the 'byte' command use for?
mov byte ptr [XXX], YY
is actually the same as mov [XXX], YY
it's just better to understand when you read the code, so I prefer it