flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Display the result of a registry addition

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
Mino



Joined: 14 Jan 2018
Posts: 160
Hello Smile
I have one more question if you do not mind:

How to display a value or a string without using printf or a C function, without anything in fact?

I know that there is the "int" statement to use system interrupts. I try this from another website (using x86 intel asm):

Code:
...
push msg
int 21h
...
    


But it does not work :'(

What would you advise me?
Post 24 Jan 2018, 16:00
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1318
int instruction is for DOS or 32-bit Linux. It's a system call. You don't need a system call to print on Windows.

You can use WriteFile (Windows API, kernel32.dll) to write to the console directly, without printf. But it's more complicated. (you also have to obtain the stdout handle). That's the "lowest level" you can get, probably. Since Windows is based on user-mode APIs (libraries, DLLs) and all system calls are hidden (and they change amongst Windows versions! but APIs don't).

printf probably ends up calling WriteFile anyway.

BTW, "call" is also an instruction, just like "int". The difference is that the latter switches to kernel mode (and thus calls a system function).
Post 24 Jan 2018, 16:02
View user's profile Send private message Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 160
OK thanks a lot Smile
And when we use "int" then?
Post 24 Jan 2018, 16:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16135
Location: Hyperborea
Mino wrote:
OK thanks a lot Smile
And when we use "int" then?
That depends upon your OS. In Windows you wouldn't ever need to use it (in theory at aleast), in Linux you can use either syscall or int 0x80. If you are writing some BIOS interface code then you use int for everything. If you are programming bare-metal then you don't use it at all unless for your functions.
Post 24 Jan 2018, 16:57
View user's profile Send private message Visit poster's website Reply with quote
yeohhs



Joined: 19 Jan 2004
Posts: 171
Location: N 5.43564° E 100.3091°
Mino wrote:

How to display a value or a string without using printf or a C function, <snipped>?
What would you advise me?


There is FASMLIB where many useful functions (including I/O) are implemented in asm. FASMLIB comes with source.
You can download it from here. http://fasmlib.x86asm.net/

There is also BASELIB from fasmnewbie.
https://sourceforge.net/projects/baselibs/files/
or
https://plus.google.com/108856344528527240894

_________________
“It’s not that we have a short time to live, but that we waste a lot of it.”
-Lucius Annaeus Seneca
Post 24 Jan 2018, 22:26
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 160
Hello again!
I would like to know why, after compiling my file, it appears as such:

Image

The executable works, but it's a little annoying to have to be in Admin to run it.

Do you have any idea Smile ?

PS: Thank you for the answer, I hadn't seen it Embarassed
Post 25 Jan 2018, 17:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16135
Location: Hyperborea
What code are you running? What OS are you using? Does your code try to write to any protected directories? Are you trying to access low level functions?
Post 25 Jan 2018, 17:50
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 160
Quote:
What code are you running?

I tried with the sent program, during the 1st post
Quote:
What OS are you using?

Windows 10
Quote:
Does your code try to write to any protected directories? Are you trying to access low level functions?

It's possible, but frankly, I don't know.
Post 26 Jan 2018, 07:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16135
Location: Hyperborea
The first post has this code:
Code:
mov eax, 7
add eax, 3
; Print what's in eax     
But did you wrap it in a DOS format or a Windows (GUI or console) format? Or some other format?

Normally programs won't need to be admin unless you are accessing protected resources. If you post the code you assembled we can probably help you.
Post 26 Jan 2018, 07:31
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 160
The code is exactly the same as the file sent, but here it is anyway:
Code:
;----------------------------------------------------------
; Program Name: integeradd
; Purpose     : integer addition
; Date        : August 2008
; Author      : Yeoh HS
; FASM        : Built using Flat Assembler version 1.67.27
;               edited and compiled with FASM's IDE.
;----------------------------------------------------------
format PE CONSOLE 4.0
entry start

include 'win32a.inc'

section '.data' data readable writeable
    val1      dd  7
    val2      dd  3

section '.code' code readable executable
start:
    ;mov eax, [val1]
    mov eax, [val2]
    add [val1], eax

    stdcall show_me, dfmt,intval,[val1]

    stdcall waitforchar
    invoke  ExitProcess,0

;---------------------------------------------------------
;   Proc to show values of data variables.
;---------------------------------------------------------
proc show_me, fmt, prompt, val
    cinvoke printf, [fmt], [prompt], [val]
    cinvoke printf, strfmt, CRLF
    ret
endp

;----------------------------------------------------------
;  Proc to prevent console window from closing immediately
;----------------------------------------------------------
proc waitforchar
   cinvoke printf, strfmt, CRLF
   cinvoke printf, strfmt, msg
   cinvoke getchar
   ret
endp

section '.data' data readable writeable

    CRLF      db '',13,10,0  ; carriage return and linefeed

    dfmt      db '%s = %d',0
    intval    db 'Integer value',0

    strfmt    db  '%s',0
    msg       db  'Press the Enter key...',0


section '.idata' import data readable writeable

library kernel32,'kernel32.dll',\
        user32,  'user32.dll',\
        msvcrt,  'msvcrt.dll'

include 'api\kernel32.inc'
include 'api\user32.inc'

import msvcrt,\
       printf, 'printf',\
       getchar,'getchar'

; end of file =================================================================

    
Post 26 Jan 2018, 11:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16135
Location: Hyperborea
AFAICT there is nothing in that code that will need admin privilege.

Can you run the example "hello world!" code that comes with fasm?
Post 26 Jan 2018, 18:58
View user's profile Send private message Visit poster's website Reply with quote
Mino



Joined: 14 Jan 2018
Posts: 160
An "Hello, world!" GUI program, from the FASM examples:
Code:
include 'win32ax.inc'

.code

  start:
        invoke  MessageBox,HWND_DESKTOP,"Hello, world!",invoke GetCommandLine,MB_OK
        invoke  ExitProcess,0

.end start
    

What's strange is that if I change (drag and drop) the generated application, ADMIN mode is no longer required.
Post 26 Jan 2018, 20:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.