News:

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

MasmBasic

Started by jj2007, October 06, 2009, 08:24:57 PM

Previous topic - Next topic

jj2007

Quote from: oex on December 04, 2009, 02:44:26 AM
:lol sorry 2am and still writing code, the distraction was most welcome

Hey, write some MasmBasic code, I want to see if it can be crashed :bg

oex

It has color :bg too high level for me, I wouldnt know where to start :lol
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

eatstoomuchjam


I was recently inspired to try MASM32 again after a fairly long hiatus and this MASMBASIC looks like fun so I thought I'd give it a try, but I'm running into a couple of problems and I'm hoping the gurus can help out.

The first one is that there isn't much documentation on Input() other than to use it after Open(), but


.data
    InBuffer$ dd

.code
    Open "O",#1,"C:\temp\file.txt"
    Print #1, "This is a test",13,10
    Close #1

    Open "I", #2, "C:\temp\file.txt"
    Input #2, InBuffer$, Lof(#2)
    Close #2

    Print InBuffer$


I would assume that the above could would result in "This is a test" being printed to my screen, but I get back nothing.  I assume it's a simple usage error and if I had the source, I'd be glad to poke at it first to see where I've goofed up.  Since it's a black box to me for the time being, I thought I'd ask.
I'm mostly interested in using Input() as I'm trying to process XML in a memory-efficient way and loading entire large XML files into memory using Recall() and/or FileRead() would put me out of the running.

Next, support for brackets may be broken in the Instr() function (and possibly others) (or again, perhaps I'm just a bit slow today).

Print "!<testing!>",13,10

Works exactly as expected

However, I get compiler errors with each of the following...

  mov esi,Instr_(0,Test$(n),"<")
  mov esi,Instr_(0,Test$(n),"!<")


But something like the following works fine.

  mov esi,Instr_(0,test$(n),"x")


Thanks in advance for any help!

eatstoomuchjam

Another problem -
I'm not certain why, but passing a value in a dd or in a register to Instr() as the first parameter results in a crash...
e.g.

.data
               curpos dd ?

.code
                mov curpos,Instr_(0,Test$(n)," ", 4)
                inc curpos
                Print Str$("%i",curpos)
                Print Str$("%i",Instr_(curpos,Test$(n)," ", 4)),13,10


In my case, that will print "2" (since the first space in the string being processed is at position #2) and then crash.

jj2007

Hello Jan (assuming that is a valid short name ;-)

First of all, welcome to the forum :thumbu
And welcome to MasmBasic. It's still far from being perfect, but I hope that I can help you overcome these problems one by one.
In case you use the RichMasm editor, select e.g. Print and press F1 for help. You would get this:
Quote MbPrint
   Print "Test", CrLf$, Chr$("the library", 13, 10)
   Print #1, esi, " is ", My$
Rem   - predefined strings CrLf$, Tb$, Spc1$, Spc2$, Spc4$, MbExeFolder$ do not bloat the exe
   - Unicode can be printed to a file as e.g. wPrint #1, wChr$(13, 10, "This is Unicode") or by defining a
     string like this: wData MyWide$, "This is Unicode", 0, followed by wPrint #1, offset MyWide$
Key   pri, pri1
Now that does look straightforward, but keep in mind that MasmBasic is not Basic: it's a Masm library, a kind of "inline Basic". Therefore, if you allocate...
.data
    InBuffer$ dd
... it means you allocated the 4 bytes that hold the pointer to the string. To read in the 16 bytes, you still need the buffer. There are (at least) two ways to do this:
1. You allocate it by hand, e.g. in the .data? section (but that requires that you know the size in advance):
.data
    InBuffer$ dd TheBuffer
.data?
TheBuffer db 20 dup(?) ; a few bytes more

2. You let (pun intended) MasmBasic do the job:
Quote    Open "O",#1,"C:\temp\file.txt"
    Print #1, "This is a test",13,10
    Close #1
    Open "I", #2, "C:\temp\file.txt"
    ; same: Let InBuffer$=New$(Lof(#2))
    Let
InBuffer$=String$(Lof(#2), 0)
    Input #2, InBuffer$, Lof(#2)
    Close

Re brackets, that is a tricky problem with the assembler itself. Exclamation marks help sometimes but not always. What I usually do is define the brackets in the .data section:
.data
LeftB$ dd txLeftBracket
RightB$ dd txRightBracket
txLeftBracket db 60, 0
txRightBracket db 62, 0

Let me know if that is sufficient to get your code running, and don't hesitate to post here, or if it does not look of general interest, PM me.

jj2007

Quote from: eatstoomuchjam on December 05, 2009, 09:43:10 PM
Another problem -
I'm not certain why, but passing a value in a dd or in a register to Instr() as the first parameter results in a crash...

I can assure you this is not "by design". I hope I can fix it tonight... sorry!

eatstoomuchjam

Thanks a lot!  I'll give your suggestions a try!

(And Dan is my name - you could call me that or ETMJ for short.  :) )

eatstoomuchjam

You suggestions for both file input and for brackets seem to be working like a charm!

Thanks a lot!  I really dig MASMBASIC, btw.  It's pretty great to have some friendly string parsing functions available.

jj2007

Quote from: eatstoomuchjam on December 05, 2009, 10:31:39 PM
You suggestions for both file input and for brackets seem to be working like a charm!

Thanks a lot!  I really dig MASMBASIC, btw.  It's pretty great to have some friendly string parsing functions available.

Hi Dan,
Great to hear it works. It seems I could solve the Instr_ problem, too - see version 9b on top of this thread. Let's call it the Santa Claus edition :bg

Note that the default start position for Instr is 1, as for most Basic dialects. If you specify zero (or less), the search continues at the previous position plus one.

For the curious, here the new Instr_ macro:
Quote; A: has startpos:   INSTR(curpos, "Test", "Te", 2)   ; 4 args
; B: no startpos:   INSTR("Test", "Te", 2)   ; 3 args, last one immediate
; C: has startpos:   INSTR(curpos, "Test", "Te")   ; 3 args, last one not immediate
; D: no startpos:   INSTR("Test", "Te")      ; 2 args, or 3 and last one immediate
Instr_ MACRO sPos, Src$, Sub$, sMode
LOCAL last_imm
  ifnb <sMode>
   push sMode               ;; A: 4 args, easiest case
   push reparg_offset(Sub$)
   PushString Src$
   push sPos
  elseifnb <Sub$>
   last_imm INSTR <0123456789>, <Sub$>
   if last_imm
      push Sub$               ;; B: 3 args, last one immediate, so sPos=Src, Src=Sub
      push reparg_offset(Src$)      ;; Sub$
      PushString sPos         ;; Src$
      push 1                  ;; added: default startpos
   else
      push 0                  ;; C: 3 args, last one not immediate, so it has sPos, added: default mode
      push reparg_offset(Sub$)
      PushString Src$
      push sPos
   endif
  else
   push 0                  ;; D: 2 args, added: default mode
   push reparg_offset(Src$)      ;; Sub$
   PushString sPos         ;; Src$
   push 1                  ;; added: default startpos
  endif
 
call InstrCi            ;; invoke InstrCi, sPos, reparg_offset(Src$), reparg_offset(Sub$), sMode
  EXITM <edx>         ;; relative pos in edx, absolute in eax
ENDM

eatstoomuchjam

Awesome.  I just gave the new one a try and not only did it fix the bug I'd run into before, but it also fixed the one I'd just logged back in to report.  :)
(Thanks for the reminder on 1-based strings in Basic - I'd run into that the hard way already.  :) )

I was also getting crashes when trying to use an array value as the search string...
e.g.

  Let curString="/test2/test"
  Dim Checks$(2)
  mov checkCount,2
  Let Checks$(0)="/test1"
  Let Checks$(1)="/test2/test"
  Let Checks$(2)="/test3/test/test"

  For_ p=0 to checkCount
    mov edi,Instr_(1,curString,Checks$(p))
  Next


Anyway, that seems to work now too... Thanks again!

jj2007

Quote from: eatstoomuchjam on December 06, 2009, 12:33:26 AM
I was also getting crashes when trying to use an array value as the search string...
e.g.

    mov edi,Instr_(1,curString,Checks$(p))

That one was related to the previous crash. Glad to see it works - keep me posted :bg

jj2007

Minor change in the RichMasm editor:
Alt K toggles between bookmarks and display of keyboard shortcuts as shown below.

db "Alt K  Toggle keys/bookmarks", 0  ; show/hide this text
db "Alt F  File menu", 0
db "Alt T  Format menu", 0
db "Alt Y  SysApps menu", 0
db "Alt H  Help menu", 0
db "Alt A  AutoCode", 0
db "Alt S  Save as", 0
db "Ctrl S  Save", 0
db "Ctrl P  Print", 0
db "Ctrl C  Copy", 0
db "CtShift C  Copy plain", 0  ; Control Shift copies plain text
db "Ctrl V  Paste", 0
db "CtShift V  Paste plain", 0
db "Ctrl D  Bookmark", 0
db "Ctrl K  HyperlinK", 0  ; insert hyperlink (prefilled if http... is on clipboard)
db "Ctrl G  Goto line", 0  ; also used for some special functions, e.g. fnt=80 for extra large font
db "CtShift O  Goto offset", 0  ; sets current line as zero and asks for an offset
db "Ctrl F  Find", 0
db "Ctrl R  Replace", 0
db "Ctrl down  Current as top line", 0
db "Ctrl up  Current as bottom", 0
db "Ctrl B  Bold", 0
db "CtShift B  Blue", 0
db "Ctrl E  Red (emphasize)", 0
db "Ctrl H  Hilight", 0
db "CtShift H  Hide", 0
db "Ctrl I  Italics", 0
db "Ctrl L  Large", 0   ; Control Shift L is XXL font
db "Ctrl N  Convert Number", 0  ; shows selected number in hex, dec and bin format
db "Ctrl U  Upper/Lowercase", 0
db "Alt left, F2  Go back", 0
db "Alt right  Go forward", 0
db "Alt L  List matches", 0
db "F1  Mb Help", 0
db "F2  Go back", 0
db "F3  Find selected", 0  ; finds all matches for selected text and shows them in a listbox
db "F4  Comment", 0  ; toggles comment
db "F5  JavaScript", 0  ; saves content as plain text to filename.js and activates browser
db "F6  Build & Run", 0  ; MASM: assemble, link, start executable
db "F7  Output window", 0  ; show/hide the F6 output window
db "F11  Copy2Forum", 0, 0  ; copy formatted code compatible with the Masm32 forum quote syntax

ic2

Wow jj2007  From Day-1 you came in with back-to-back projects in mind.  Be back soon.

ic2

I really done nothing ASM for a long time.  When I went dead-beat you were talking consoles and font's.  I came back last night to find those threads. I want to write a few web applications in ASM under Windows but 100% potable to FREEBSD and LINUX and with Window-7 I think Microsoft made it easy.  If I'm on the right track, a few of your old threads are going to get me started (consoles style system-font scaling, color font, etc).  Maybe old news by now, but here Mark Russinovich drops a clue about UNIX mode under Windows-7.  He say nothing about where is it or if it is the real deal.  But if you can write it under windows and it is build ready for a real linux/BSD machine with minimum modification, if any, that's going to make a easy dive :).  I'm crazy about Windows but not as a public server.

http://channel9.msdn.com/shows/Going+Deep/Mark-Russinovich-Inside-Windows-7-Redux/

http://channel9.msdn.com/shows/Going+Deep/Mark-Russinovich-Inside-Windows-7/

Anyway, I'm looking at RichMasm and when I size and place a program windows at my idea location on the screen, that's where I want it to be the next time I open it up.  How do we setwindowpos for RichMasm window?  I see no ini-file for RichMasm editor or a Windows registry key.  If you include x-y position, I hope you use a ini-files for RichMasm.

ic2

This is it, right ... your editor is a console, GUI style where you went beyond 16 bit command.com which is what cmd.exe for XP tried to leave DOS behind, but where win-system only show dialog style window for console so I'll take that back about inifile ... You got full-screen and I remember googling and concluded, there not a easy way to make adjustments if ever any.  If I'm guesting right, that will work but how about FASM.