flat assembler
Message board for the users of flat assembler.

Index > Non-x86 architectures > in fasmarm it is possible to code something like this

Thread Post new topic Reply to topic

Joined: 24 Mar 2012
Posts: 785
Location: Russian Federation, Sochi
ProMiNick 14 May 2018, 10:02
;format PE CEGUI 2.11 at $10000
format PE GUI 2.11 at $10000;rename binary as 'winCE.EXE'

entry start   ;launch CMD line '%OUTPUT%'

include 'wincew.inc'

section '.text' code readable executable

        ;invoke  GetModuleHandle,0 ; {MOV R0, #0; BL GetModuleHandle}
        ;STR     R0, [wc.hInstance]
        STR     R4, [wc.hInstance] ; Initialy R4 holds hInstance
        LDR     R1, WindowProc
        STR     R1, [wc.lpfnWndProc]
        MOV     R1, COLOR_BTNFACE+1
        STR     R1, [wc.hbrBackground]
        LDR     R1, _class
        STR     R1, [wc.lpszClassName]
        invoke  LoadIcon,R0,IDI_APPLICATION ; {MOV R1, IDI_APPLICATION; BL LoadIcon}
        STR     R0, [wc.hIcon]
        invoke  RegisterClass,wc ; {LDR R0, wc; BL RegisterClass}
        CMP     R0,#0
        BEQ     error
        invoke  CreateWindowEx,0,_class,_title,$10000000,0,0,100,100,NULL,NULL,[wc.hInstance],NULL ; {MOV R0, #0; LDR R1, _class; LDR R2, _title; MOV R3, $10000000; (MOV R5, NULL; STR R5, [SP]), (LDR R5, [wc.hInstance]; STR R5, [SP-4]), (MOV R5, NULL; STR R5, [SP-8]), (MOV R5, NULL; STR R5, [SP-12]), (MOV R5, 100; STR R5, [SP-16]), (MOV R5, 100; STR R5, [SP-20]), (MOV R5, 0; STR R5, [SP-16]), (MOV R5, 0; STR R5, [SP-20]), later 4 nulls for 4 params via registers; BL CreateWindowEx}
        CMP     R0,#0
        BEQ     error

        invoke  GetMessage,msg,NULL,0,0 ; {LDR R0, msg; MOV R1, NULL; MOV R2, #0; MOV R3, #0; BL GetMessage}
        CMP     R0, #0
        BEQ     end_loop
        invoke  TranslateMessage,msg ; {LDR R0, msg; BL TranslateMessage}
        invoke  DispatchMessage,msg ; {LDR R0, msg; BL DispatchMessage}
        B       msg_loop

        invoke  MessageBox,NULL,_error,NULL,MB_ICONERROR+MB_OK ; MOV R0, NULL; LDR R1, _error; MOV R2, NULL; MOV R3, MB_ICONERROR+MB_OK; BL MessageBox}

        ;invoke  ExitProcess,0
        MOV     R0,#0
        MOV     PC,$F000F7F8 ;B $F000F7F8; ExitProcess=$F000F7F8?

proc WindowProc uses R4 R5 R6 R7 R8 R11 LR, hwnd,wmsg,wparam,lparam
        CMP     R1,WM_DESTROY
        BEQ     .wmdestroy
        invoke  DefWindowProc,R0,R1,R2,R3
        B       .finish
        invoke  PostQuitMessage,0 ; {MOV R0, #0; BL PostQuitMessage}
        MOV     R0,#0

section '.data' data readable writeable

  _class TCHAR 'FASMWINCE',0
  _title TCHAR 'WinCE program template',0
  _error TCHAR 'Startup failed.',0

  wc WNDCLASS style:0, lpfnWndProc:WindowProc, hbrBackground:COLOR_BTNFACE+1, lpszClassName:_class
  msg MSG

section '.idata' import data readable writeable
  ;DCD 0,0,0,RVA coredll_name,RVA coredll_table
  ;dd 0,0,0,0,0

  ;  ExitProcess dd RVA _ExitProcess
  ;  dd 0

  ;coredll_name db 'COREDLL.DLL',0

  ;LoadIcon dw 0
  ;  db 'LoadIconW',0
  ;RegisterClass dw 0
  ;  db 'RegisterClassW',0
  ;CreateWindowEx dw 0
  ;  db 'CreateWindowExW',0
  ;GetMessage dw 0
  ;  db 'GetMessageW',0
  ;TranslateMessage dw 0
  ;  db 'TranslateMessage',0
  ;DispatchMessage dw 0
  ;  db 'DispatchMessageW',0
  ;MessageBox dw 0
  ;  db 'MessageBoxW',0
  ;DefWindowProc dw 0
  ;  db 'DefWindowProcW',0
  ;PostQuitMessage dw 0
  ;  db 'PostQuitMessageW',0

    library coredll,'COREDLL.DLL'

  include 'ABI\WINCE\API\coredll.inc'     

where is correct formatter includes & macros to ARM format variations & ARM OSes

question: registers R0-R3 for calls 1st 4 args, what is the best register for temp calculations? to make some things via macro?
(I would prefer to change order of STR instruction to Intel like syntax).
Why I try ARM in wince - it small, easy to emulate & it structures & apies looks like windows structures & apies. this is skeleton of app, for now wincew.inc & ceredll.inc - not exists.

I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 14 May 2018, 10:02
View user's profile Send private message Send e-mail Reply with quote
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20070
Location: In your JS exploiting you and your system
revolution 14 May 2018, 10:38
Yes, you could make all the various macros to do that if you wanted.

The register usage for calls will follow the ARM call standard. R4-R11 to be preserved. R0-R3, R12 volatile. R13 stack. R14 return address. R15 is PC. And R12 is used by the ARM compiler for long jumps/calls.
Post 14 May 2018, 10:38
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.