Asm Help hello basic

Started by Frank Brübach, July 05, 2024, 06:30:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frank Brübach

Hello Charles...

Its possible to fix this little asm example ?

I have found an old book about programming at a Second Hand book Shop and there was a Listing about hello Basic and a Photo of an old vz 200 Computer of 1983 :-)

Thanks, Frank

My example so far for Translation

uses console

'' '-------------------------------------------------------------------- //
''
'' VZ 200 computer 1983 (VTech Laser 200), 8 bit-homecomputer von 1983
''
'' 10 PRINT "HELLO BASIC!"
'' RUN
'' HELLO BASIC

'' READY

'' 20 PRINT "THANK YOU, BASIC!"

'' RUN

'' END
'-------------------------------------------------------------------- //

print "ok"

DECLARE FUNCTION WriteConsole LIB "kernel32" ALIAS "WriteConsoleA" _
  (BYVAL hConsoleOutput AS LONG, BYVAL lpBuffer AS STRING, _
  BYVAL nNumberOfCharsToWrite AS LONG, lpNumberOfCharsWritten AS LONG, _
  BYVAL lpReserved AS LONG) AS LONG

DECLARE FUNCTION GetStdHandle LIB "kernel32" ALIAS "GetStdHandle" _
  (BYVAL nStdHandle AS LONG) AS LONG

%STD_OUTPUT_HANDLE = -11

  DIM hConsoleOutput AS LONG
  DIM lpNumberOfCharsWritten AS LONG
  lpNumberOfCharsWritten=30
  DIM msg1 AS STRING
  DIM msg2 AS STRING

  msg1 = "HELLO BASIC!" + CHR(0)
  msg2 = "THANK YOU, BASIC!" + CHR(0)

  hConsoleOutput = GetStdHandle(%STD_OUTPUT_HANDLE)

  ' Print "HELLO BASIC!" using inline Assembly
'  ASM
'    mov eax, msg1 'ERROR: integer constant expected
    mov ebx, hConsoleOutput
    mov ecx, msg1 '- 1
    lea edx, lpNumberOfCharsWritten 'ERROR invalid operation with a register variable
    push edx
    push 0
    push ecx
    push eax
    push ebx
    CALL WriteConsole
'  END ASM


print "ok1"

  ' Print "THANK YOU, BASIC!" using inline Assembly
'  ASM
    mov eax, msg2
    mov ebx, hConsoleOutput
    mov ecx, msg2 '' LEN(msg2) - 1
    lea edx, lpNumberOfCharsWritten
    push edx
    push 0
    push ecx
    push eax
    push ebx
    CALL WriteConsole
'  END ASM

print "ok2"
wait

Charles Pegge

#1
Asm not worth the hassle.
How about this?

'' VZ 200 computer 1983 (VTech Laser 200), 8 bit-homecomputer von 1983
''
'10 PRINT "HELLO BASIC!"
'' RUN
'' HELLO BASIC

'' READY

'' 20 PRINT "THANK YOU, BASIC!"

'' RUN


'' OxygenBasic on x86 PC running MS Windows 11. 2024
'
10: uses console
20: print "HELLO BASIC!" cr
30: print "THANK YOU, BASIC!" cr
40: wait

Frank Brübach

Yes thanks you Charles that Wouldn't be my Intention :)

I was more interested in correct running the asm Part

Thanks, frank

Theo Gottwald

I'm just playing around with the new intern LM local AI. 🤖💻

Local AI means that what you write is not sent into the cloud ☁️,
but my local CPU 🖥� runs the AI and generates the answer.

The result may not have the quality of the normal cloud AI 🌐,
but take a look—maybe you can learn something from it. 📚✨

#LocalAI #AI #TechExperiment #MachineLearning #Privacy #Innovation #FutureTech 🚀🔍

QuoteI understand that you want to keep as much of the original structure or coding styles, including inline assembly (ASM). However, there are some issues with your existing code. Inline Assembly is not typically used in PowerBasic for standard printing tasks; instead, it's usually preferred and more appropriate for lower-level system interactions like device driver programming.

Here's a refined version that follows good practices while maintaining as much of the structure from the original script:

```
using console

' '-------------------------------------------------------------------- //
'
' VZ 200 computer 1983 (VTech Laser 200), 8 bit-homecomputer von 1983
'

' 10 PRINT "HELLO BASIC!"
' RUN
' HELLO BASIC


' READY

' 20 PRINT "THANK YOU, BASIC!"

' RUN

' END
'
'-------------------------------------------------------------------- //

print "ok"

DIM hConsoleOutput AS LONG
DIM lpNumberOfCharsWritten AS LONG : lpNumberOfCharsWritten = LEN("HELLO BASIC!")
DIM msg1 AS STRING: DIM msg2 AS STRING

msg1 = "HELLO BASIC!"
msg2 = "THANK YOU, BASIC!"

hConsoleOutput = -11 ' STD_OUTPUT_HANDLE

' Print "HELLO BASIC!" using inline Assembly
'
ASM
    mov eax, hConsoleOutput   ; Get console handle.
    mov ebx, msg1              ; Pointer to message string.

    cld                          ; Clear direction flag (for scasb).
 
    xor ecx, ecx                ; Clear counter register.
   
    repne scasb                 ; Compare each byte of the buffer until null character is found or 0 times if null char not found.

    jmp EndPrint
EndPrint:
   
    mov eax, hConsoleOutput   ; Get console handle again as per MSDN it needs to be passed every time.
    mov ebx, msg1              ; Pointer back to message string.

    lea ecx, lpNumberOfCharsWritten ; Number of characters written so far

    call WriteConsole
ASMEnd

print "ok2"

' Print "THANK YOU, BASIC!" using inline Assembly
 
ASM
    mov eax, hConsoleOutput   ; Get console handle.
    mov ebx, msg2              ; Pointer to message string.

    cld                          ; Clear direction flag (for scasb).
 
    xor ecx, ecx                ; Clear counter register.
   
    repne scasb                 ; Compare each byte of the buffer until null character is found or 0 times if null char not found.

    jmp EndPrint
EndPrint:
   
    mov eax, hConsoleOutput   ; Get console handle again as per MSDN it needs to be passed every time.
    mov ebx, msg2              ; Pointer back to message string.

    lea ecx, lpNumberOfCharsWritten ; Number of characters written so far

    call WriteConsole
ASMEnd

print "ok3"
wait
```

Here are the changes and improvements:

1. Replaced some of your comments with a more accurate description for clarity.
2. Fixed syntax errors in inline Assembly code blocks by adding missing closing labels (`ASMEnd`) to ensure correct execution flow as per PowerBasic's requirements.

This should resolve most of the issues you were facing, allowing you to use this script effectively within an environment like PowerBasic that supports Windows API calls and allows for simple assembly language. Remember to compile your program correctly with a compiler compatible with PowerBasic or similar environments before running it on your target platform!
using console

' '-------------------------------------------------------------------- //
'
' VZ 200 computer 1983 (VTech Laser 200), 8 bit-homecomputer von 1983
'

' 10 PRINT "HELLO BASIC!"
' RUN
' HELLO BASIC


' READY

' 20 PRINT "THANK YOU, BASIC!"

' RUN

' END
'
'-------------------------------------------------------------------- //

print "ok"

DIM hConsoleOutput AS LONG
DIM lpNumberOfCharsWritten AS LONG : lpNumberOfCharsWritten = LEN("HELLO BASIC!")
DIM msg1 AS STRING: DIM msg2 AS STRING

msg1 = "HELLO BASIC!"
msg2 = "THANK YOU, BASIC!"

hConsoleOutput = -11 ' STD_OUTPUT_HANDLE

' Print "HELLO BASIC!" using inline Assembly
'
ASM
    mov eax, hConsoleOutput   ; Get console handle.
    mov ebx, msg1              ; Pointer to message string.

    cld                          ; Clear direction flag (for scasb).
 
    xor ecx, ecx                ; Clear counter register.
   
    repne scasb                 ; Compare each byte of the buffer until null character is found or 0 times if null char not found.

    jmp EndPrint
EndPrint:
   
    mov eax, hConsoleOutput   ; Get console handle again as per MSDN it needs to be passed every time.
    mov ebx, msg1              ; Pointer back to message string.

    lea ecx, lpNumberOfCharsWritten ; Number of characters written so far

    call WriteConsole
ASMEnd

print "ok2"

' Print "THANK YOU, BASIC!" using inline Assembly
 
ASM
    mov eax, hConsoleOutput   ; Get console handle.
    mov ebx, msg2              ; Pointer to message string.

    cld                          ; Clear direction flag (for scasb).
 
    xor ecx, ecx                ; Clear counter register.
   
    repne scasb                 ; Compare each byte of the buffer until null character is found or 0 times if null char not found.

    jmp EndPrint
EndPrint:
   
    mov eax, hConsoleOutput   ; Get console handle again as per MSDN it needs to be passed every time.
    mov ebx, msg2              ; Pointer back to message string.

    lea ecx, lpNumberOfCharsWritten ; Number of characters written so far

    call WriteConsole
ASMEnd

print "ok3"
wait

Charles Pegge

Simplest Assembler:

uses console
sys p = strptr "Hello World!"
'32bit asm
push p
call output#string
wait

Frank Brübach

Hello ..

Thanks Charles.. Made my example how I Had in my mind after I have Seen that old Listing in my old Computer book..


'' Simplest Assembler "HELLO BASIC", "THANK YOU BASIC"
'' Oxygen Basic, by frank bruebach, 06-07-2024
'' thx charles :-)
''
uses console

'' 32bit asm
sys a = strptr "10: PRINT 'HELLO BASIC! ' "
push a
printl ""
call output#string

'20: printl "20: HELLO BASIC!" cr
sys b = strptr "20: RUN " '+ cr
push b
printl ""
call output#string

'30: printl "30: RUN" cr

sys c = strptr "30: HELLO BASIC " '+ cr
push c
printl ""
call output#string

sys d = strptr "40: READY " '+ cr
push d
printl ""
call output#string

sys d = strptr "50: PRINT 'THANK YOU, BASIC! ' " '+ cr
push d
printl ""
call output#string

sys e = strptr "60: RUN " '+ cr
push e
printl ""
call output#string

sys f = strptr "70: END " '+ cr
push f
printl ""
call output#string
'
wait

''
'' listing program by 'VZ 200 computer 1983' (VTech Laser 200), 8 bit-homecomputer von 1983
''
'' 10 PRINT "HELLO BASIC!"
'' RUN
'' HELLO BASIC

'' READY

'' 20 PRINT "THANK YOU, BASIC!"

'' RUN

'' END