News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

random ascii question

Started by marla, October 19, 2005, 12:24:07 AM

Previous topic - Next topic

marla

i have read the masm manual, and done a few tutorials. but i cannot seem to grasp this (pardon the asm newb) - i am trying to create a program that breaks the first three strings into arrays, then to use them and incremently write every possible combination to file in sequence. i am just looking for a few pointers on variables, and where i would start... thanks in advance - heres what i have so far.

; -------------------------------------------
      .486
      .model flat, stdcall
      option casemap :none
      include \masm32\include\windows.inc
      include \masm32\include\gdi32.inc
      include \masm32\include\user32.inc
      include \masm32\include\kernel32.inc
      includelib \masm32\lib\gdi32.lib
      includelib \masm32\lib\user32.lib
      includelib \masm32\lib\kernel32.lib
; -------------------------------------------

.data

   ; name points to variable first character
   _num   DB   "0123456789", 0
   _aph   DB   "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 0
   _sym   DB   "!,@,#,$,%,^,&,*,(,),{,},[,],-,_,+,=,`,~", 0

; -------------------------------------------

.code

   Start:
      MOV    EAX,   [_num]   
      MOV   EBX,   [_sym]

      PUSH   EAX
      PUSH   EBX

      MOV CX, [_num.length]
      AGAIN:
         MOVSB
         LOOP AGAIN

      MOV CX, [_sym.length]
      AGAIN:
         MOVSB
         LOOP AGAIN

      MOV CX, [_num.length]
      AGAIN:
         MOVSB
         LOOP AGAIN
   
      POP EBX
      POP EAX

      CALL ExitProcess,0
   END Start

;-------------------------------------------

hutch--

marla,

Interestingly enough, the 3 strings are already BYTE arrays and all you need to do is scan through each string until you find the terminator. You have a mix of 16 and 32 bit code that will not do the job properly. Try some of these ideas.


      ; MOV    EAX,   [_num]   ;; will not work.
      ; MOV   EBX,   [_sym]

    mov esi, OFFSET _num      ;; this is correct.


If you are going to use the old string instructions which work OK, they normaly use ESI as the source, EDI as the destination and ECX as the counter. The registers you preserve if you are going to use them are EBX ESI and EDI, EAX ECX and EDX can be freely modified so just as a hint to make your code more reliable, start with,


    push ebx
    push esi
    push edi

  ; write your code here

    pop edi
    pop esi
    pop ebx


If you don't use all of the three registers, just remove the ones you don't use.

Here is a quick example for you that may help out.


; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .data?
      buffer db 128 dup (?)

    .data
      alpha db "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",0

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

main proc

    push ebx
    push esi
    push edi

  ; ---------------------------------------
  ; copy each byte in "alpha" into "buffer"
  ; ---------------------------------------
    mov esi, OFFSET alpha
    mov edi, OFFSET buffer
    mov ecx, LENGTHOF alpha
    rep movsb

    print OFFSET buffer,13,10

  ; ------------------------------------
  ; scan through string 1 char at a time
  ; ------------------------------------
    xor eax, eax
    mov esi, OFFSET alpha
  lbl:
    mov al, [esi]           ; copy byte in ESI to AL
    test al, al             ; test if it is zero terminator
    jz outlbl               ; exit the loop if it is
    add esi, 1              ; add 1 to ESI to read next byte


  ; AL has the current character at this location
    print str$(eax),13,10

    jmp lbl                 ; loop back and read next byte

  outlbl:

    pop edi
    pop esi
    pop ebx

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

marla

i wasnt really sure how to use your compile instructions. however i get the following error when i use my make.bat file:
make.bat:[
PATH=c:\masm32\bin;%PATH%
@echo off
ml /c /coff 2.asm
link /subsystem:windows 2.obj
pause>nul
]

could not find: include \masm32\include\masm32rt.inc
...

thx for the help though, very interesting!