the reason begin every console asm "hello world" i study they all looking different from each other.

#include <iostream.h>
int main()
{
cout << "Hello";
}


thx
Posted on 2002-03-25 06:28:09 by k0d
This should help ya.... handles input and output... just copy, paste & compile to see what it's doing!

regards,
bAZiK

P.S.: This is better than you C++ crap:


#include <stdio.h>
void main() { printf("Hello!"); }


ANSI-C rulez! :grin:



--------------------------------------------------------------------------------
; ###############################

.386
.model flat, stdcall
option casemap :none

; ###############################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\shell32.inc

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

; ###############################

CPut PROTO :DWORD
CPutErr PROTO :DWORD
CGet PROTO
GetCmd PROTO
ListLong PROTO
ChangeDir PROTO
Execute PROTO

; ###############################

.data
; ################## console strings
szConTitle db "WinShell Konsole v0.10", 0
szConAbout db "Copyright 2001 by bAZiK", 13,10, 0
szNewLine db 13, 10, 0
szError db "Error: Command or File not found!", 13,10,13,10, 0
szTimeFormat db "HH:mm:ss", 0
szDateFormat db "dd.MM.yyyy", 0
szChgError db "Error: Directory not found!", 13,10, 0
szShellError db "Error: File not found!", 13,10, 0

; ################## console commands
szExit db "exit", 0
szll db "ll", 0
szcd db "cd", 0
szx db "x", 0

; ################## wsprintf templates
szConPrompt db "%s > ", 0
szListFormat db "%s %s %s %35s %13lu", 0
szTotalFormat db "Total Size: %lu Byte(s)", 13,10, 0

; ################# structures
wfd WIN32_FIND_DATA <>
syst SYSTEMTIME <>
ft FILETIME <>

; ###############################

.data?
szOutputBuffer db 512 dup (?)
szInputBuffer db 512 dup (?)
szCmdBuffer db 512 dup (?)
szDirBuffer db 512 dup (?)
szListBuffer db 512 dup (?)
szAttribBuffer db 20 dup (?)
szTimeBuffer db 20 dup (?)
szDateBuffer db 20 dup (?)
szTotalBuffer db 512 dup (?)
szChgBuffer db 512 dup (?)
szShellBuffer db 512 dup (?)
hFind dd ?
hInput dd ?
hOutput dd ?
hWritten dd ?
hRead dd ?
hMenu dd ?
hConWin dd ?
lpTotalSize dd ?

; ###############################

.code

start:
invoke GetStdHandle, STD_INPUT_HANDLE
mov hInput, eax
invoke GetStdHandle, STD_OUTPUT_HANDLE
mov hOutput, eax
invoke SetConsoleTitle, addr szConTitle

invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_GREEN or \
FOREGROUND_BLUE or \
FOREGROUND_INTENSITY or \
BACKGROUND_BLUE
invoke CPut, addr szConTitle
invoke CPut, addr szNewLine
invoke CPut, addr szConAbout
invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_GREEN or \
FOREGROUND_BLUE or \
FOREGROUND_INTENSITY
invoke CPut, addr szNewLine

@@:
call CGet
call GetCmd
cmp byte ptr [szCmdBuffer], 0 ; return gedr?ckt
je @B

invoke lstrcmp, addr szCmdBuffer, addr szExit
.if eax == 0
jmp @F
.endif

invoke lstrcmp, addr szCmdBuffer, addr szll
.if eax == 0
call ListLong
jmp @B
.endif

invoke lstrcmp, addr szCmdBuffer, addr szcd
.if eax == 0
call ChangeDir
invoke CPut, addr szNewLine
jmp @B
.endif

invoke lstrcmp, addr szCmdBuffer, addr szx
.if eax == 0
call Execute
invoke CPut, addr szNewLine
jmp @B
.endif

invoke CPutErr, addr szError
jmp @B
@@:

invoke ExitProcess, 0

; ###############################

Execute proc
invoke RtlZeroMemory, addr szShellBuffer, 512
lea edi, szInputBuffer
lea esi, szShellBuffer
add edi, 2 ; 'x '
@@:
mov al, byte ptr [edi]
cmp al, 13
je @F
mov byte ptr [esi], al
inc edi
inc esi
or al, al
jnz @B
@@:
invoke ShellExecute, 0, 0, addr szShellBuffer, 0, \
addr szDirBuffer, SW_SHOWNORMAL
cmp eax, ERROR_FILE_NOT_FOUND
jne @F

invoke CPutErr, addr szShellError
@@:
ret

Execute endp

; ###############################

ChangeDir proc
invoke RtlZeroMemory, addr szChgBuffer, 512
lea edi, szInputBuffer
lea esi, szChgBuffer
add edi, 3 ; 'cd '
@@:
mov al, byte ptr [edi]
cmp al, 13
je @F
mov byte ptr [esi], al
inc edi
inc esi
or al, al
jnz @B
@@:
invoke SetCurrentDirectory, addr szChgBuffer
cmp eax, 0
jne @F

invoke CPutErr, addr szChgError
@@:
ret
ChangeDir endp

; ###############################

ListLong proc
mov eax, 0
mov lpTotalSize, eax

invoke CPut, addr szNewLine
invoke lstrlen, addr szDirBuffer
lea edi, szDirBuffer
add edi, eax
mov byte ptr [edi], 42 ; *

invoke FindFirstFile, addr szDirBuffer, addr wfd
mov hFind, eax

@@:
lea edi, szAttribBuffer
mov eax, wfd.dwFileAttributes

.if (eax & FILE_ATTRIBUTE_DIRECTORY)
mov byte ptr [edi], 100 ; d
.else
mov byte ptr [edi], 45 ; -
.endif

inc edi

.if (eax & FILE_ATTRIBUTE_ARCHIVE)
mov byte ptr [edi], 97 ; a
.else
mov byte ptr [edi], 45 ; -
.endif

inc edi

.if (eax & FILE_ATTRIBUTE_SYSTEM)
mov byte ptr [edi], 115 ; s
.else
mov byte ptr [edi], 45 ; -
.endif

inc edi

.if (eax & FILE_ATTRIBUTE_HIDDEN)
mov byte ptr [edi], 104 ; h
.else
mov byte ptr [edi], 45 ; -
.endif

inc edi

.if (eax & FILE_ATTRIBUTE_READONLY)
mov byte ptr [edi], 114 ; r
.else
mov byte ptr [edi], 45 ; -
.endif

invoke FileTimeToLocalFileTime, addr wfd.ftLastWriteTime, addr ft
invoke FileTimeToSystemTime, addr ft, addr syst
invoke GetTimeFormat, 0, 0, addr syst, \
addr szTimeFormat, addr szTimeBuffer, 20
invoke GetDateFormat, 0, 0, addr syst, addr szDateFormat, \
addr szDateBuffer, 20

mov eax, MAXDWORD
mov ebx, wfd.nFileSizeHigh
imul ebx
add eax, wfd.nFileSizeLow
mov edx, eax

add lpTotalSize, edx

invoke wsprintf, addr szListBuffer, addr szListFormat, \
addr szAttribBuffer, addr szDateBuffer, \
addr szTimeBuffer, addr wfd.cFileName, edx

invoke CPut, addr szListBuffer
invoke CPut, addr szNewLine

invoke RtlZeroMemory, addr szListBuffer, 512 ; clear buffer
invoke FindNextFile, hFind, addr wfd
invoke GetLastError
cmp eax, ERROR_NO_MORE_FILES
jne @B

invoke CPut, addr szNewLine

invoke wsprintf, addr szTotalBuffer, addr szTotalFormat, lpTotalSize
invoke CPut, addr szTotalBuffer

invoke CPut, addr szNewLine
invoke CloseHandle, hFind

ret
ListLong endp

; ###############################

CPutErr proc lpText:DWORD
invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_INTENSITY
invoke CPut, lpText
invoke SetConsoleTextAttribute, hOutput, FOREGROUND_RED or \
FOREGROUND_GREEN or \
FOREGROUND_BLUE or \
FOREGROUND_INTENSITY
ret
CPutErr endp

; ###############################

CPut proc lpText:DWORD
invoke lstrlen, lpText
invoke WriteFile, hOutput, lpText, eax, addr hWritten, 0
mov eax, hWritten
ret
CPut endp

; ###############################

CGet proc
invoke RtlZeroMemory, addr szDirBuffer, 512
invoke GetCurrentDirectory, 512, addr szDirBuffer
lea edi, szDirBuffer
add edi, eax
cmp byte ptr [edi-1], "\"
je @F
mov byte ptr [edi], "\"
@@:
invoke wsprintf, addr szOutputBuffer, addr szConPrompt, addr szDirBuffer
invoke CPut, addr szOutputBuffer
invoke RtlZeroMemory, addr szInputBuffer, 512
invoke ReadFile, hInput, addr szInputBuffer, 512, addr hRead, 0
mov eax, hRead
ret
CGet endp

; ###############################

GetCmd proc
invoke RtlZeroMemory, addr szCmdBuffer, 512
lea edi, szInputBuffer
lea esi, szCmdBuffer
@@:
mov al, byte ptr [edi]
cmp al, 32
je @F
cmp al, 13
je @F
mov byte ptr [esi], al
inc edi
inc esi
or al, al
jnz @B
@@:
ret
GetCmd endp

; ###############################

end start

; ###############################
Posted on 2002-03-25 07:09:44 by bazik
i've already tryed it, run it thx , but i am looking for "hello" so i could practive the opcodes this way i get familiar with them.
But every "hello" console i found differ from one another. so i am looking for plain hello console so i know whats going in the code.

bazik you got to think about what c++ means:

C See
++ Increment ONE
Posted on 2002-03-25 07:30:55 by k0d
build with:

ml /c /coff hello.asm
link /subsystem:console hello.obj
Posted on 2002-03-25 10:26:05 by malone
this is exactly what i was looking for.
Posted on 2002-03-26 01:03:10 by k0d