Groups | Search | Server Info | Login | Register
Groups > comp.sys.acorn.programmer > #6510
| From | Theo <theom+news@chiark.greenend.org.uk> |
|---|---|
| Newsgroups | comp.sys.acorn.programmer |
| Subject | Re: File type of machine code? Where does it start? |
| Date | 2025-06-08 11:02 +0100 |
| Organization | University of Cambridge, England |
| Message-ID | <lKm*MFveA@news.chiark.greenend.org.uk> (permalink) |
| References | <5c294dfd2cbavariasound@chiemgau-net.de> |
Alexander Ausserstorfer <bavariasound@chiemgau-net.de> wrote: > What is the file type of machine code? In Bruce Smith book "Raspberry Pi > Assembly Language" he saves a block of memory with the command *save > <filename> <startaddr>+<length>. The saved file has no file type. By a > double click the code is running from the desktop in single mode, though. > > Where do I find the starting point of such a code? What is the address > where the machine code is starting? This is the territory of executable formats. When you assemble some code in BASIC, it's assembled to a particular address which is whereever it happened to be stored in your program. eg: DIM buf% 100 P%=buf [MOV R0, #42: MOV PC, R14 PRINT USR buf% will assemble the code to run at whatever address buf% happened to be allocated when you ran the program, which depends on the other things in memory (like the length of your program) If instead of the DIM you wrote: buf% = &A000 then the code would be assembled to start at a fixed address of &A000. (But you wouldn't do this because if you made the program longer you'd end up assembling the code over the top of it and corrupting it) If you *Save mycode A000+8 it'll produce an untyped file with load/exec address &A000. If you run this, the OS will make a new application slot, load the code to address &A000 and run it. The code is unable to be run at any address except &A000. Exec addresses are mostly a hangover from the BBC Micro and it's strongly recommended not to use them. Generally you don't want to write code that way because you need it to run in a certain environment. Outside of running things from inside BASIC there are three main environments in which code runs: 'Application' - Absolute &FF8 filetype - expected to have an Acorn Image File (AIF) header. Runs at &8000 in its own application slot. Code need not be position-independent code (PIC) because it knows it's loaded at &8000. When you run an Absolute from the desktop the OS will create a fresh Wimpslot for it so it can run at &8000 as it expects. If you run an Absolute from within another application (eg BASIC) you should expect it to overwrite the current application - ie you won't be able to return to your BASIC program again because it's been overwritten. 'Relocatable Module' - Module &FFA - with module header with various entry points. OS allocates some space in the relocatable module area (RMA) and loads it there. Code must be PIC because we don't know the address beforehand. Runs with operating system privilege (supervisor mode rather than user mode) which allows access to more functionality (eg can answer SWI calls and add *commands) but easier to crash system. 'Utility' - Utility &FFC - designed for small standalone programs like providing disc-based *commands. Runs position-independent in user mode, but doesn't allocate its own Wimpslot (ie doesn't start a full application or turf out the application currently running). Gets its own user stack but must be able to run PIC as it could be loaded anywhere in memory. If you're going to be writing programs you want to run by double clicking or by *command, probably simplest to get started is the Utility. You don't have to deal with getting the various headers and entry points right that you need for your own AIF or module. If you're going to be writing full applications (eg multitasking) then you likely need an application slot and that means AIF. (or perhaps an Application Module, but that's more advanced) > On the Commodore 64 (or Mega65) you will type > > SYS <address> to start machine code at address. From BASIC you can: CALL <address> : starts the code at that address, no results returned Variables A% to H% supply r0-r7 (there's also more advanced ways to pass parameters) ret%=USR <address> : starts the code, returns the value of r0 into ret% A% etc work as above For the CLI you can also: *Run mycode - execute file 'mycode', assuming it has an executable filetype (FF8/FFA/FFC) or an execution address *Go <address> - start code at a given address. Note this may wipe out the current application context, eg if you run it from BASIC it may return to a * prompt and wipe your BASIC program. > When I examine an absolute file in StrongEd (dump mode), the first line > always at address 8000. Is this also the starting point of the code? Originally this was just a big block of code to start at &8000. Often executables were compressed and so the first instruction was a branch to the decompression code. Nowadays there's a requirement for an AIF header and if you just make a lump of code without a header you may find the system complains it's not 32-bit compatible if it can't find the '32 bit ok' flag in the right place in the header. But aside from the modern requirement to have a header it's still just code expecting to be loaded at &8000 - you just need to provide an entry point in the header that will be called, rather than directly jumping to &8000 as in the old days. Paolo has a good overview here: https://paolozaino.wordpress.com/2020/08/07/risc-os-introduction-to-the-arm-aif-object-file-format/ (there's a lot more stuff targeted at C programmers, but basically all you really care about is the EntryPoint and the Address mode flag to say it's 32 bit compatible) Theo
Back to comp.sys.acorn.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
File type of machine code? Where does it start? Alexander Ausserstorfer <bavariasound@chiemgau-net.de> - 2025-06-07 17:41 +0200
Re: File type of machine code? Where does it start? Martin <News03@avisoft.f9.co.uk> - 2025-06-07 18:14 +0100
Re: File type of machine code? Where does it start? Alexander Ausserstorfer <bavariasound@chiemgau-net.de> - 2025-06-08 18:26 +0200
Re: File type of machine code? Where does it start? Theo <theom+news@chiark.greenend.org.uk> - 2025-06-08 11:02 +0100
Re: File type of machine code? Where does it start? Alexander Ausserstorfer <bavariasound@chiemgau-net.de> - 2025-06-08 18:32 +0200
Re: File type of machine code? Where does it start? Alexander Ausserstorfer <bavariasound@chiemgau-net.de> - 2025-06-19 07:22 +0200
Re: File type of machine code? Where does it start? Jean-Michel <jmc.bruck@orange.fr> - 2025-06-19 11:23 +0200
Re: File type of machine code? Where does it start? druck <news@druck.org.uk> - 2025-06-24 20:47 +0100
Re: File type of machine code? Where does it start? Bob Latham <bob@sick-of-spam.invalid> - 2025-06-25 09:29 +0100
Re: File type of machine code? Where does it start? Martin <News03@avisoft.f9.co.uk> - 2025-06-19 10:48 +0100
Re: File type of machine code? Where does it start? Alexander Ausserstorfer <bavariasound@chiemgau-net.de> - 2025-06-20 17:22 +0200
Re: File type of machine code? Where does it start? Matthew Phillips <spam2011m@yahoo.co.uk> - 2025-06-21 08:20 +0100
Re: File type of machine code? Where does it start? Theo <theom+news@chiark.greenend.org.uk> - 2025-06-20 17:25 +0100
csiph-web