Open ecm-pushbx opened 2 years ago
This is the header containing the packed structures used by the source: https://hg.pushbx.org/ecm/interc3/file/77616b6c4040/intercep.h
#include <stdint.h>
/* what we record in our memory block about each interrupt */
typedef struct __attribute__ ((__packed__)) {
uint16_t bp, di, si, ds, es, dx;
uint16_t cx, bx, ax;
uint16_t ip;
uint16_t cs;
uint16_t flags;
uint16_t intnum;
} swi_info;
typedef struct __attribute__ ((__packed__)) {
uint8_t vendor[8];
uint8_t product[8];
uint16_t offset;
uint16_t segment;
uint16_t version;
uint16_t reserved;
uint16_t intnum;
} swi_info_amis;
The example source that produces this code is at https://pushbx.org/ecm/test/20211114/test.c
It is taken from https://hg.pushbx.org/ecm/interc3/file/77616b6c4040/INTERPRE.C#l184 (The interpre source is in the Public Domain, intercep component under Fair License.)
While trying to shrink the required example code the register allocation seemed to change so that the code in question wasn't produced any longer. That's why the test.c file has the entire
interpret_file
function.The C source is compiled as
ia16-elf-gcc -Wall -fpack-struct -mcmodel=small -Os test.c -masm=intel -S -o test.s
This is the relevant code:
This is the assembly generated from this source:
The part that I made this feature request for is:
The
add
with an immediate could be folded into thelea
.Bonus optimisation:
I believe
test ah, ah
would be one byte shorter.