NO

Author Topic: I am begginer  (Read 11760 times)

zellJunior

  • Guest
I am begginer
« on: February 05, 2014, 09:17:49 PM »
Please someone help me adapt this code to POASM
/------------------------------------------------------------------/
               TITLE salut1_exe
               .MODEL    SMALL
               .STACK    100h
               .DATA
     mesaj     DB   "Salut!",13,10
     lmesaj    EQU  $ mesaj
               .CODE
     start:    mov  ax,@data
               mov  ds,ax
               mov  bx,1
               mov  cx,lmesaj
               mov  dx,OFFSET mesaj
               mov  ah,40h
               int  21h
               mov  ax,4C00h
               int  21h
               END  start

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: I am begginer
« Reply #1 on: February 05, 2014, 10:07:11 PM »
Your code is 16-bit, that won't work with PoAsm. Here is an example that compiles fine but requires some libraries from Masm32:
.486         ; create 32 bit code
.model flat, stdcall   ; 32 bit memory model
option casemap :none   ; case sensitive

include \masm32\include\windows.inc   ; main windows include file
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.code
AppTitle   db "PoAsm is great:", 0
AppName   db "Hi, I am a MessageBox", 0

start:
   invoke MessageBox, 0, addr AppName, addr AppTitle, MB_OK
   invoke ExitProcess, 0

end start

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: I am begginer
« Reply #2 on: February 05, 2014, 10:33:14 PM »
PoAsm (just like Pelle's C in general) is geared towards development for (32/64bit) Windows programming.
Your assembler code is for a 16bit .COM style DOS code, which PoAsm therefor doesn't understand...

Instead of using JJ's cryptic code to force a Windows executable with a different assembler, I think a better option to get you going with your x86 assembly language studies is to use JWasm, which is likely to compile your source code just fine.

However, as this will (when linked) produce a 16bit .COM executable file, you can't run this on any 64bit flavor of Windows, as in those, the backwards compatibility that would enable you to run 16bit code has been removed. Any 32bit version of Windows however should be fine...

Ralf

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: I am begginer
« Reply #3 on: February 05, 2014, 10:37:58 PM »
For POAsm without any extra stuff:
Code: [Select]
.486         ; create 32 bit code
.model flat, stdcall   ; 32 bit memory model
option casemap :none   ; case sensitive

MB_OK EQU 0h
MessageBoxA proto :DWORD, :DWORD, :DWORD, :DWORD
ExitProcess proto : DWORD

includelib kernel32.lib
includelib user32.lib

.code
AppTitle   db "PoAsm is great:", 0
AppName   db "Hi, I am a MessageBox", 0

start:
   invoke MessageBoxA, 0, addr AppName, addr AppTitle, MB_OK
   invoke ExitProcess, 0

end start
May the source be with you

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: I am begginer
« Reply #4 on: February 05, 2014, 10:59:20 PM »
However, as this will (when linked) produce a 16bit .COM executable file..

Beisser, fyi this will produce a 16-bit .exe, not .com
The example above was assembled with PoAsm, not with "a different assembler"; besides, I find your attempt to push the OP to continue with JWasm and 16-bit code utterly anachronistic.

@Timo: Thanks for simplifying the example.

zellJunior

  • Guest
Re: I am begginer
« Reply #5 on: February 05, 2014, 11:09:34 PM »
Thanks a lot to all, i need to study more POASM structure. A very good example from "timovjl" <-- thanks. I would appreciate if someone wold give an example how to shoe "Hello" to console. 

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: I am begginer
« Reply #6 on: February 05, 2014, 11:25:48 PM »
Sure, here it is:

.486         ; create 32 bit code
.model flat, stdcall   ; 32 bit memory model
option casemap :none   ; case sensitive

includelib kernel32.lib

.code
TheMessage   db "PoAsm is great:", 0

ConOut proc lpszText, sl
LOCAL bytesWritten
   invoke GetStdHandle, -11   ; STD_OUTPUT_HANDLE
   xchg eax, ecx
   invoke WriteFile, ecx, lpszText, sl, addr bytesWritten, 0
   ret
ConOut endp

start:   
   invoke ConOut, addr TheMessage, sizeof TheMessage
   invoke ExitProcess, 0
end start

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: I am begginer
« Reply #7 on: February 05, 2014, 11:33:12 PM »
Simpler minimal version:
Code: [Select]
.486         ; create 32 bit code
.model flat, stdcall   ; 32 bit memory model
option casemap :none   ; case sensitive

includelib kernel32.lib

ExitProcess proto : DWORD
GetStdHandle    PROTO :DWORD
WriteFile       PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

.data
msg   db "PoAsm is great!",13,10,0
numw  dd 0

.code
start:
   invoke GetStdHandle, -11
   invoke WriteFile, eax, addr msg, sizeof msg, addr numw, 0
   invoke ExitProcess, 0
end start
When using debugger this one using PROC and ENDP works better:
Code: [Select]
.486         ; create 32 bit code
.MODEL FLAT, STDCALL   ; 32 bit memory model
OPTION CASEMAP :NONE   ; case sensitive

INCLUDELIB kernel32.lib

ExitProcess  PROTO :DWORD
GetStdHandle PROTO :DWORD
WriteFile    PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD

.data
msg   db "PoAsm is great!",13,10,0
numw  dd 0

.code
start PROC
   INVOKE GetStdHandle, -11
   INVOKE WriteFile, eax, ADDR msg, SIZEOF msg, ADDR numw, 0
   INVOKE ExitProcess, 0
start ENDP
END start
« Last Edit: February 06, 2014, 07:47:08 AM by timovjl »
May the source be with you

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: I am begginer
« Reply #8 on: February 05, 2014, 11:34:42 PM »
... besides, I find your attempt to push the OP to continue with JWasm and 16-bit code utterly anachronistic.
Given that he states in his (her?) subject that (s)he is a beginner, without any indication of what his/her problem is (s)he ran into and what the purpose for trying to get this exact example, which is clearly 16bit DOS based code (hence INT21h calls), I think that referring to a cleaner, DOS based assembler is rather appropriate than anachronistic.
Understanding how x86 assembler works is one thing, understanding what is required to get this working in Windows is a completely different ball game.

Basics never change, environments do...

Ralf

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: I am begginer
« Reply #9 on: February 05, 2014, 11:48:38 PM »
without any indication of what his/her problem is

Please someone help me adapt this code to POASM

This is what Timo and I have done. Re environments, for console apps the switch from DOS to Win32 is not a big issue.

zellJunior

  • Guest
Re: I am begginer
« Reply #10 on: February 06, 2014, 08:37:26 AM »
Ok. i analyzed this code, i see that we declare 3 procedures : GetStdHandle,..., and then we call  them in "main" procedure with invoke. But i am a little confused. When i debug a C code, i see there a lot of "ADD","MOV","SUB"...<-- mnemonics.they miss from this code. I also know, assembler works with registers: ax,bx,cx,dx,eax,ebx,...
so : mov ax,10  ;means we move 10 to ax register.
my question is - what does the : (invoke GetStdHandle, -11) function. I changed -11 with other number and there is nothing shown.

Reading anachronistic's reply carefully, i think i cannot program in POASM for embeded systems.
« Last Edit: February 06, 2014, 08:44:56 AM by zellJunior »

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: I am begginer
« Reply #11 on: February 06, 2014, 09:46:03 PM »
without any indication of what his/her problem is

Please someone help me adapt this code to POASM

This is what Timo and I have done. Re environments, for console apps the switch from DOS to Win32 is not a big issue.
You missed that he clearly stated to be a beginner, and the source code he posted is a 16 bit DOS equivalent of a Hello World in x86 assembler.

The fact that he is/was trying to adapt this to PoASM is rather due to the effect that this is what he has at hand as a tool (as included in Pelle's C). And as stated by me, PoASM and 16 bit code simply don't mix.

You in fact did more then just adapting his program to PoASM, you rather adapted a 16bit DOS program to a 32bit Windows console application. And in his latest reply, he clearly states that he is even more confused by your adaptation...

"If someone's only tool he knows to use is a hammer, everything looks like a nail"...

Ralf

Offline Bitbeisser

  • Global Moderator
  • Member
  • *****
  • Posts: 772
Re: I am begginer
« Reply #12 on: February 06, 2014, 09:59:29 PM »
Ok. i analyzed this code, i see that we declare 3 procedures : GetStdHandle,..., and then we call  them in "main" procedure with invoke. But i am a little confused. When i debug a C code, i see there a lot of "ADD","MOV","SUB"...<-- mnemonics.they miss from this code. I also know, assembler works with registers: ax,bx,cx,dx,eax,ebx,...
so : mov ax,10  ;means we move 10 to ax register.
my question is - what does the : (invoke GetStdHandle, -11) function. I changed -11 with other number and there is nothing shown.
That's what I referred to in my latest reply to JJ, they not only adapted the code to to PoASM, they made a Windows program out of it.

They pretty much replaced to the direct screen output via INT21h of your initial (DOS) code posted with the more (much) complicated way of processing screen output via Windows handles, in effect changing your running environment, which for a beginner (as you called yourself) is indeed much  more confusing....
Quote
Reading anachronistic's reply carefully, i think i cannot program in POASM for embeded systems.
If you referring to my post (my name is Ralf, as you can see as I sign each and every post of mine (with some rare exceptions) with my real (first) name), then that is indeed what I was getting at.

You are presenting a DOS based program, using very specific DOS based services (INT21h is the DOS service interrupt) that simply do not exist/aren't allowed anymore in real Windows programs (as mentioned your program,  when compiled and linked as true 16bit code won't run on any of the 64bit Windows versions anymore).
And PoASM (together with the rest of the Pelle's C programming environment) are specifically geared to create Windows programs. That is why I still think that it is the best option if you are using a tool (like JWAsm) that is more adapt to your task...

PoIDE works very nicely as an editor with syntax highlighting for any kind of x86 assembler code (that is actually one of the purposes I am using it myself for), but if you want to create plain DOS (or embedded as you eluded to) programs, you a tool specifically suited for that task.

Ralf

tienkhoanguyen

  • Guest
Re: I am begginer
« Reply #13 on: October 25, 2014, 05:35:34 PM »
 :)  Well, I specifically develop for the DOS environment using Borland Turbo C and Borland Turbo Assembler.  Both are DOS based however the Assembler has a version which also compiles for 32-bit mode in Windows.  Since I have specialized using the 8086 chip which is DOS, I can give an example of an assembly using my tool.  I hope it works for you.  Sorry if I am kind of late, and a permanent friendly hello to everyone.

p8086
model small
dataseg
udataseg
stack 100h
codeseg
startupcode

mov dl, 'U'
mov ah, 2
int 21h

mov ah, 04ch
mov al, 0
int 21h

end

Okay this only prints out the word 'U' as in You.  However it illustrates the use of interrupts which is the main cooking ingredientes for DOS assembly programming.  hehe

tienkhoanguyen

  • Guest
Re: I am begginer
« Reply #14 on: November 02, 2014, 11:56:33 AM »
 :)  I am a dork.  I just noticed the original poster wanted to adapt a Borland Turbo Assembler program to a version by Pelles.  I do not know Pelles, however, I can tell you what the program does so anyone who wants to help can adapt it.  The program simply states "Salut!" then it goes to the next line with a line feed character.  After that it tabs over and exit.

Cheers!