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
LVL 1
lewis_looAsked:
Who is Participating?
 
RheingoldCommented:
Greetings

I don't believe that you can shorten your reverse procedure using push/pop combinations. I recoded your reverse proc in this way:

reverse proc near
  lea si, namefld
  lea di, namefld
  ;;xor bx, bx - INCLUDE THIS IF YOU USE BX BEFORE - NOT NECESSARY, BECAUSE BX WILL BE 0 HERE
  mov bl, namelen
  dec bl
  mov cl, namelen
  shr cl, 1

  up: ; -----------------------| DECREASED YOUR LOOP FROM 17 LINES TO 8
  mov al, byte ptr [si+bx]   ; | MOV/XCHG/INC/DEC/JNZ HAVE ALL 1 CYCLE ON
  xchg al, byte ptr [di]     ; | PENTIUM MACHINES
  mov byte ptr [si+bx], al   ; |
  inc di                     ; |
  dec bl                     ; |
  dec cl                     ; |
  jnz up ;---------------------|
  mov bl, namelen ;; THOSE TWO LINES ARE
  mov byte ptr [si+bx], '$' ;; USED TO TERMINATE THE STRING
ret
reverse endp

Tell me if you don't understand the code

Regards
Rheingold
0
 
Jan LouwerensSoftware EngineerCommented:
Is this a school assignment?
0
 
lewis_looAuthor Commented:
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
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
lewis_looAuthor Commented:
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
0
 
lewis_looAuthor Commented:
What it the 'byte' command use for?
0
 
RheingoldCommented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.