News:

Download Pelles C here: http://www.pellesc.se

Main Menu

Not frustrated enough? Too much spare time?

Started by Pelle, March 30, 2026, 10:09:19 AM

Previous topic - Next topic

Pelle

Well, why not try writing some ARM64 (RISC) assembly code?

Here is a small example for POASM, displaying a typical "Hello, world" message box:

NULL            equ     0
MB_OK           equ     0
EXIT_SUCCESS    equ     0

                area .rdata, data, readonly

message         dcb     "Hello, Windows on ARM64!", 0
title           dcb     "POASM test", 0

                area .text, code

                export main

                import __imp_ExitProcess
                import __imp_MessageBoxA

main            function

                stp     fp,lr,[sp,#-16]!
                mov     fp,sp

                mov     x0,NULL
                adrp    x1,message
                add     x1,x1,message
                adrp    x2,title
                add     x2,x2,title
                mov     w3,MB_OK
                adrp    x8,__imp_MessageBoxA
                ldr     x8,[x8,__imp_MessageBoxA]
                blr     x8

                mov     w0,EXIT_SUCCESS
                adrp    x8,__imp_ExitProcess
                ldr     x8,[x8,__imp_ExitProcess]
                blr     x8

                ldp     fp,lr,[sp],#16
                ret       

                endfunc

                end

The C version is just a tad shorter:

int main(void) {
  MessageBoxA(NULL, "Hello, Windows on ARM64!", "POASM test", MB_OK);
  ExitProcess(EXIT_SUCCESS);
}
/Pelle

Vortex

#1
Hi Pelle,

Thanks for the ARM64 example. I don't have a computer with an ARM processor, so not easy to the test sample. Thanks for maintaining Poasm. Yes, the C version is shorter and is looking better.
Code it... That's all...

Pelle

Quote from: Vortex on March 30, 2026, 09:09:29 PMThanks for the ARM64 example. I don't have a computer with an ARM processor, so not easy to the test sample. Thanks for maintaining Poasm. Yes, the C version is shorter and is looking better.
I have seen some hints on the web that Windows 11 (on X64) may be able to emulate ARM64 code (not just using the weird ARM64EC mode). I can't verify this myself since my only Windows 11 machine right now is a laptop with an ARM64 processor.
/Pelle

John Z

I'd really like to be able to do that.  However a brief check came up with this -

"AI Overview
No, standard
x64 Windows 11 cannot directly run ARM64 applications or host an ARM64 virtual machine using native hardware virtualization. Hyper-V on x64 hardware does not support running ARM64 operating systems. To run ARM64 apps, you must use a device powered by an Arm-based processor (such as Windows on ARM or Apple Silicon)."

Sadly,

John Z

Pelle

Right. Apparently it was the other way around: emulating X86/X64 on ARM. Oh, well...
/Pelle

Vortex

Qemu for Windows can emulate ARM64, ChatGPT says :

qemu-system-aarch64 \
  -machine virt \
  -cpu cortex-a72 \
  -m 4G \
  -bios QEMU_EFI.fd \
  -drive file=windows_arm.qcow2,if=virtio \
  -device virtio-net-device \
  -netdev user,id=n1

QuoteBut expect trial-and-error with:

Storage drivers
Display (often -device ramfb or virtio-gpu)
Code it... That's all...

John Z

Thanks Vortex!

Nice find - https://www.qemu.org/docs/master/system/target-arm.html

"QEMU can emulate both 32-bit and 64-bit Arm CPUs. Use the qemu-system-aarch64 executable to simulate a 64-bit Arm machine. You can use either qemu-system-arm or qemu-system-aarch64 to simulate a 32-bit Arm machine: in general, command lines that work for qemu-system-arm will behave the same when used with qemu-system-aarch64."

Guess Google AI not so much I  ;D

Not sure how hard to set up, but I'll be reading more.  Won't be windows on ARM but command line capability I'm supposing, unless a ARM Windows ISO can be involved.

John Z

Vortex

Code it... That's all...

PabloMack

#8
The gymnastics that ARM64 has to go through to come up with these string addresses is amazingly bad.

TimoVJL

Pelles C C-compiler support ARM64, why not just use it.
An assembler is just for making some useful functions using CPU in best way.
May the source be with you

PabloMack

#10
I think it is a good thing to understand (and even discuss) the limitations of everything you use. Otherwise there will likely never be improvement.

Vortex

It looks like that the assembly coders have to pay the simplification of the RISC architecture. The opposite is the previous CISC system.
Code it... That's all...