Solved

Assembly Language Problem

Posted on 2000-04-16
3
333 Views
Last Modified: 2010-05-18
I have really been battling on this program the whole weekend and I hope that you can help me . What the program does is accept command line parameters -typed in after the program name in dos-
and then it is supposed to reverse those parameters e.g. if the program is called rev.exe then in dos you would type : rev the old man
the  program should print the parameter "the old man" backwards thus the program should print man old the. I have already done about 80% of the program i.e. it grabs the command line parameters and then it scans through those parametrs to find the occurence of an "&" character and everytime it finds that specific character it pushes the offset of that character onto the stack i.e. I uses scasb and the character is stored at ed:di and everytime a match is found di is pushed onto the stack. Now what I wanted to do was to pop a di of the stack and then print every string that way i.e. pop di
mov dx,di and then call dos function 09h to print the string then I want to place a $ at the position [es:di] as when th next di gets popped off dos will only print form that di to the position where I put an $ at [es:di] but for some reason it does not work :

Here is my program I would really appreciate it if you could help me finish this program its really difficult and rather urgent thanks Koopa.
DOSSEG
.MODEL SMALL
.STACK 200h
.DATA
  string db ?

.CODE

PROC Print
  mov ah,09h
  int 21h
ENDP Print


PROC GetCommandLine
;es:di = pointer to command line parameter
;cx = length of string in bytes
;bx = last address of the string

   mov ah,62h
   int 21h
   mov es,bx
   mov bx,81h
   add bl,byte ptr [es:80h]

   mov ch,0
   mov cl,byte ptr [es:80h]

   mov ax,"$"
   mov [es:bx],ax
   mov di,81h
 
   ret
ENDP GetCommandLine


START:
 
  call GetCommandLine   ;initalize es:di basically
  mov al,"&"            ;we are going to search the string
                        ;for a &

  mov dx,0 ;counter=0
  cld      ;count forward basically

  scan:  repne scasb       ;repeat if not equal
    je found               ;if you find somwthing then jump
                           ;to the found section
   found:
   
      push di  ;save the value of di on the stack  
               ;di is the current location of the character
               ;we were looking for
       inc dx   ;counter = counter + 1
       cmp cx,0 ;have we scanned through the whole string    
                ;remember cx was initalized by getCommandLine
      jne scan ;if not carry on scanning remember di is
               ;still the same value as it was
 
    ;After this piece of code everything is put nicely onto the
    ;stack for us now we have to do is pop it off to get the
    ;relative offset values which is stored in di
       
      mov ax,es
      mov ds,ax  ;lets set up our data segment
     
     
       pop di   ;get rid of the last character

       pop di  ;dx = the value on the stack
       mov dx,di

       call print    
 
       mov ax,"$"
       mov [es:di-1],ax

       pop di

               
       mov dx,di
       call print  
   

                 
     
     mov ax,4c00h  ;return control to dos
     int 21h




 END START
0
Comment
Question by:koopa
  • 2
3 Comments
 

Author Comment

by:koopa
ID: 2720945
Please could you also try to put some loop at the end of the question to automatically print the string backwards ?
0
 
LVL 1

Accepted Solution

by:
Rheingold earned 200 total points
ID: 2722091
Hi

here's my solution for this problem. I needed to change the GetCommandLine procedure, because I had problems with the [es:bx] addressing (I'm no DOS-ASM coder; In Win32Asm you have nice 32bit linear addresses ;) - If you get the idea you can easily adjust this to your procedure.

DOSSEG
..MODEL SMALL
..STACK 200h

..DATA
counter db ?
string db ?

..CODE

GetCommandLine PROC
  mov counter, 0 ;; COUNTER FOR PARAMETERS
  pop bx ;; POP THE RETURN ADDRESS FOR THE CALL
  mov ah, 2 ;; FOR DOS-FUNCTION 02h - DISPLAY CHAR
  mov si, 80h ;; COMMANDLINE
  lodsb ;; GET LENGTH OF CMDLINE
  cmp al, 0 ;; LENGHT = 0 ?
  je no_cmdline ;; NO COMMANDLINE
  mov cl, al ;; INITIALIZE COUNTER FOR LOOP
  xor ch, ch
loop1: lodsb
  cmp al, " " ;; NEXT PARAM?
  jne @NoPush
  push si ;; PUSH ADDY OF PARAM ON STACK
  inc counter ;; ONE MORE PARAMETER
  @NoPush:
  loop loop1 ;; GET NEXT CHAR
no_cmdline:
  push bx ;; SAVE RETURN ADDY FOR THE CALL
  ret
GetCommandLine ENDP

START:

call GetCommandLine

@NextParam:
mov dl, 20h ;; PRINT ONE SPACE
int 21h
dec counter ;; DECREASE COUNTER
cmp counter, 0FFh ;; ALL PARAMS PRINTED?
je @NoCmd ;; FINISH
pop si ;; GET ADDY OF PARAMETER
@GoOn:
lodsb ;; GET A CHAR
cmp al, 0Dh ;; PARAMLINE SEEMS TO BE 0D/00 TERMINATED
je @NextParam ;; NEXT PARAM
cmp al, " "
je @NextParam ;; NEXT PARAM

@NotYet:
mov dl, al ;; PRINT
int 21h    ;; CHAR
jmp @GoOn

@NoCmd:
mov ax, 4C00h
int 21h
END START
0
 

Author Comment

by:koopa
ID: 2723747
Thank you so much for the help I really appreciate it !
Koopa
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
linearIn  challenge 23 65
countAbc challenge 9 49
C Programming - If Statement 8 48
C# DataGridView_RowsAdded event not firing 1 37
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now