Solved

assembly (string)

Posted on 2000-03-29
6
497 Views
Last Modified: 2012-06-21
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
0
Comment
Question by:lewis_loo
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:Jan Louwerens
ID: 2666869
Is this a school assignment?
0
 
LVL 1

Author Comment

by:lewis_loo
ID: 2669736
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
 
LVL 1

Author Comment

by:lewis_loo
ID: 2669738
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 1

Accepted Solution

by:
Rheingold earned 50 total points
ID: 2676286
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
 
LVL 1

Author Comment

by:lewis_loo
ID: 2678759
What it the 'byte' command use for?
0
 
LVL 1

Expert Comment

by:Rheingold
ID: 2685222
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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here we come across an interesting topic of coding guidelines while designing automation test scripts. The scope of this article will not be limited to QTP but to an overall extent of using VB Scripting for automation projects. Introduction Now…
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question