### GNU Mes --- Maxwell Equations of Software
### Copyright © 2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
### Copyright © 2018 Peter De Wachter <pdewacht@gmail.com>
### Copyright © 2022 Ekaitz Zarraga <ekaitz@elenq.tech>
###
### This file is part of GNU Mes.
###
### Mes is free software# you can redistribute it and/or modify it
### under the terms of the GNU General Public License as published by
### the Free Software Foundation# either version 3 of the License, or (at
### your option) any later version.
###
### GNU Mes is distributed in the hope that it will be useful, but
### WITHOUT ANY WARRANTY# without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with GNU Mes.  If not, see <http://www.gnu.org/licenses/>.

# reduced instruction set: rax, rdi (some rcx for shift, rdx for mul, div)
# and r10 as i64 immediate helper
# 212 instructions

DEFINE add____$i32,%rax 4805
DEFINE add____$i32,%rbp 4881c5
DEFINE add____$i32,%rdi 4881c7
DEFINE add____$i32,(%rax) 8100
DEFINE add____$i32,0x32(%rbp) 8185
DEFINE add____$i8,%rax 4883c0
DEFINE add____$i8,%rdi 4883c7
DEFINE add____$i8,%rsp 4883c4
DEFINE add____$i8,(%rax) 8300
DEFINE add____$i8,(%rdi) 8307
DEFINE add____$i8,0x8(%rbp) 8345
DEFINE add____%r15,(%rax) 4c0138
DEFINE add____%r15,(%rdi) 4c013f
DEFINE add____%rax,%rax 4801c0
DEFINE add____%rbp,%rax 4801e8
DEFINE add____%rdi,%rax 4801f8
DEFINE add____%rdi,%rdi 4801ff
DEFINE addb___$i8,(%rax) 8000
DEFINE addb___$i8,(%rdi) 8007
DEFINE addl___$i32,(%rax) 8100
DEFINE addl___$i32,(%rdi) 8107
DEFINE addl___$i8,(%rax) 8300
DEFINE addl___$i8,(%rdi) 8307
DEFINE addw___$i8,(%rax) 668100
DEFINE addw___$i8,(%rdi) 668107
DEFINE and____$i32,%rdi 4881e7
DEFINE and____%r15,%rax 4c21f8
DEFINE and____%r15,%rdi 4c21ff
DEFINE and____%rdi,%rax 4821f8
DEFINE call32 e8
DEFINE call___*%rax ffd0
DEFINE call___*%rdi ffd7
DEFINE cmp____$i32,%rax 483d
DEFINE cmp____$i8,%rax 4883f8
DEFINE cmp____$i8,%rdi 4883ff
DEFINE cmp____%r15,%rax 4c39f8
DEFINE cmp____%r15,%rdi 4c39ff
DEFINE cqto 4899
DEFINE div___%rdi 48f7f7
DEFINE hlt f4
DEFINE idiv___%rdi 48f7ff
DEFINE ja32  0f87
DEFINE jae32 0f83
DEFINE jb32  0f82
DEFINE jbe32 0f86
DEFINE je32 0f84
DEFINE je8 74
DEFINE jg32 0f8f
DEFINE jge32 0f8d
DEFINE jl32 0f8c
DEFINE jle32 0f8e
DEFINE jmp32 e9
DEFINE jmp____*%rbx ffe3
DEFINE jne32 0f85
DEFINE lahf 9f
DEFINE mov____$i32,%rax 48c7c0
DEFINE mov____$i32,%rdi 48c7c7
DEFINE mov____$i32,0x8(%rbp) c745
DEFINE mov____$i64,%r15 49bf
DEFINE mov____$i64,%rax 48b8
DEFINE mov____$i64,%rdi 48bf
DEFINE mov____$i8,%al b0
DEFINE mov____$i8,%rax b0
DEFINE mov____%al,(%rdi) 8807
DEFINE mov____%al,0x32(%rbp) 8885
DEFINE mov____%al,0x8(%rbp) 8845
DEFINE mov____%ax,(%rdi) 668907
DEFINE mov____%ax,0x8(%rbp) 668945
DEFINE mov____%eax,%eax 89c0
DEFINE mov____%eax,%rax 89c0
DEFINE mov____%eax,(%rdi) 8907
DEFINE mov____%eax,0x32(%rbp)  8985
DEFINE mov____%eax,0x8(%rbp) 8945
DEFINE mov____%edi,%edi 89ff
DEFINE mov____%edi,%rdi 89ff
DEFINE mov____%edi,0x32(%rbp) 89bd
DEFINE mov____%edi,0x8(%rbp) 897d
DEFINE mov____%esi,%eax 89f0
DEFINE mov____%esi,(%rdi) 8937
DEFINE mov____%r8,%rdi 4c89c7
DEFINE mov____%rax,%rax 4889c0
DEFINE mov____%rax,%rdi 4889c7
DEFINE mov____%rax,(%rdi) 488907
DEFINE mov____%rax,0x32 48890425
DEFINE mov____%rax,0x32(%rbp) 488985
DEFINE mov____%rax,0x8(%rbp) 488945
DEFINE mov____%rax,0x8(%rdi) 488947
DEFINE mov____%rbp,%rax 4889e8
DEFINE mov____%rbp,%rdi 4889ef
DEFINE mov____%rbp,%rsp 4889ec
DEFINE mov____%rbp,0x8(%rbp) 48896d
DEFINE mov____%rdi,%r8 4989f8
DEFINE mov____%rdi,%rax 4889f8
DEFINE mov____%rdi,%rcx 4889f9
DEFINE mov____%rdi,%rdi 4889ff
DEFINE mov____%rdi,0x32 48893c25
DEFINE mov____%rdi,0x32(%rbp) 4889bd
DEFINE mov____%rdi,0x8(%rbp) 48897d
DEFINE mov____%rdx,%rax 4889d0
DEFINE mov____%rdx,%rdi 4889d7
DEFINE mov____%rsi,(%rdi) 488937
DEFINE mov____%rsp,%rbp 4889e5
DEFINE mov____%si,(%rdi) 668937
DEFINE mov____%sil,(%rdi) 448837
DEFINE mov____(%rax),%eax 8b00
DEFINE mov____(%rax),%esi 8b30
DEFINE mov____(%rax),%rax 488b00
DEFINE mov____(%rax),%rsi 488b30
DEFINE mov____(%rax),%si 668b30
DEFINE mov____(%rax),%sil 408a30
DEFINE mov____(%rdi),%edi 8b3f
DEFINE mov____(%rdi),%rdi 488b3f
DEFINE mov____0x32(%rbp),%rax 488b85
DEFINE mov____0x32(%rbp),%rdi 488bbd
DEFINE mov____0x32,%rax 488b0425
DEFINE mov____0x32,%rdi 488b3c25
DEFINE mov____0x8(%rbp),%eax 8b45
DEFINE mov____0x8(%rbp),%r10 4c8b55
DEFINE mov____0x8(%rbp),%r8 4c8b45
DEFINE mov____0x8(%rbp),%r9 4c8b4d
DEFINE mov____0x8(%rbp),%rax 488b45
DEFINE mov____0x8(%rbp),%rbp 488b6d
DEFINE mov____0x8(%rbp),%rbx 488b5d
DEFINE mov____0x8(%rbp),%rcx 488b4d
DEFINE mov____0x8(%rbp),%rdi 488b7d
DEFINE mov____0x8(%rbp),%rdx 488b55
DEFINE mov____0x8(%rbp),%rsi 488b75
DEFINE mov____0x8(%rbp),%rsp 488b65
DEFINE mov____0x8(%rdi),%rax 488b47
DEFINE mov____0x8(%rdi),%rbp 488b6f
DEFINE mov____0x8(%rdi),%rsp 488b67
DEFINE movl___%eax,0x32 890425
DEFINE movl___%edi,0x32 893c25
DEFINE movl___%esi,(%rdi) 8937
DEFINE movl___(%rax),%esi 8b30
DEFINE movsbq_%al,%rax 480fbec0
DEFINE movsbq_%dil,%rdi 480fbeff
DEFINE movsbq_(%rax),%rax 480fbe00
DEFINE movsbq_(%rdi),%rdi 480fbe3f
DEFINE movslq_%eax,%rax 4863c0
DEFINE movslq_%edi,%rdi 4863ff
DEFINE movslq_(%rax),%rax 486300
DEFINE movslq_(%rdi),%rdi 48633f
DEFINE movswq_%ax,%rax 480fbfc0
DEFINE movswq_%di,%rdi 480fbfff
DEFINE movswq_(%rax),%rax 480fbf00
DEFINE movswq_(%rdi),%rdi 480fbf3f
DEFINE movw___%ax,0x32 66890425
DEFINE movw___%di,0x32 66893c25
DEFINE movz___(%rax),%rax 480fb600
DEFINE movzbq_%al,%rax 480fb6c0
DEFINE movzbq_%dil,%rdi 480fb6ff
DEFINE movzbq_(%rax),%rax 480fb600
DEFINE movzbq_(%rdi),%rdi 480fb63f
DEFINE movzlq_%eax,%rax 89c0
DEFINE movzlq_%edi,%rdi 89ff
DEFINE movzlq_(%rax),%rax 8b00
DEFINE movzlq_(%rdi),%rdi 8b3f
DEFINE movzwq_%ax,%rax 480fb7c0
DEFINE movzwq_%di,%rdi 480fb7ff
DEFINE movzwq_(%rax),%rax 480fb700
DEFINE movzwq_(%rdi),%rdi 480fb73f
DEFINE mul____%rdi 48f7e7
DEFINE nop 90
DEFINE not____%rax 48f7d0
DEFINE not____%rdi 48f7d7
DEFINE or_____%rdi,%rax 4809f8
DEFINE pop____%rax 58
DEFINE pop____%rbp 5d
DEFINE pop____%rdi 5f
DEFINE pop____%rdx 5a
DEFINE push___$i32 68
DEFINE push___%r15 4157
DEFINE push___%rax 50
DEFINE push___%rbp 55
DEFINE push___%rdi 57
DEFINE push___%rdx 52
DEFINE ret c3
DEFINE sahf 9e
DEFINE seta___%al 0f97c0
DEFINE seta___%dil 400f97c7
DEFINE setae__%al 0f93c0
DEFINE setae__%dil 400f93c7
DEFINE setb___%al 0f92c0
DEFINE setb___%dil 400f92c7
DEFINE setbe__%al 0f96c0
DEFINE setbe__%dil 400f96c7
DEFINE sete___%al 0f94c0
DEFINE sete___%dil 400f94c7
DEFINE setg___%al 0f9fc0
DEFINE setg___%dil 400f9fc7
DEFINE setge__%al 0f9dc0
DEFINE setge__%dil 400f9dc7
DEFINE setl___%al 0f9cc0
DEFINE setl___%dil 400f9cc7
DEFINE setle__%al 0f9ec0
DEFINE setle__%dil 400f9ec7
DEFINE setne__%al 0f95c0
DEFINE shl____$i8,%rax 48c1e0
DEFINE shl____$i8,%rdi 48c1e7
DEFINE shl____%cl,%rax 48d3e0
DEFINE shl____%cl,%rdi 48d3e7
DEFINE shr____%cl,%rax 48d3e8
DEFINE sub____$i32,%rbp 4881ed
DEFINE sub____$i32,%rsp 4881ec
DEFINE sub____%rdi,%rax 4829f8
DEFINE syscall 0f05
DEFINE test___%al,%al 84c0
DEFINE test___%rax,%rax 4885c0
DEFINE test___%rdi,%rdi 4885ff
DEFINE xchg___%rax,%rdi 4897
DEFINE xchg___%rax,(%rsp) 48870424
DEFINE xchg___%rdi,(%rsp) 48873c24
DEFINE xor____$i8,%ah 80f4
DEFINE xor____%rax,%rax 4831c0
DEFINE xor____%rdi,%rax 4831f8
DEFINE xor____%rdx,%rdx 4831d2


# Enough for all of Mes + Mes C Libray when using all registers, i.e.,
# non-reduced instruction set
#DEFINE add____$i32,%rdx 4881c2
#DEFINE add____$i32,%rsi 4881c6
#DEFINE add____$i8,%rcx 4883c1
#DEFINE add____$i8,%rdx 4883c2
#DEFINE add____$i8,%rsi 4883c6
#DEFINE add____$i8,(%rsi) 488306
#DEFINE add____%rdx,%rdx 4801d2
#DEFINE add____%rdx,%rsi 4801d6
#DEFINE add____%rsi,%rdi 4801f7
#DEFINE add____%rsi,%rsi 4801f6
#DEFINE addl___$i32,(%rsi) 8106
#DEFINE addl___$i8,(%rsi) 8306
#DEFINE and____$i32,%rsi 4881e6
#DEFINE idiv___%rcx 48f7f9
#DEFINE idiv___%rsi 48f7fe
#DEFINE mov____$i32,%r8 49c7c0
#DEFINE mov____$i32,%r9 49c7c1
#DEFINE mov____$i32,%rcx 48c7c1
#DEFINE mov____$i32,%rdx 48c7c2
#DEFINE mov____$i32,%rsi 48c7c6
#DEFINE mov____%dil,(%rsi) 40883e
#DEFINE mov____%edi,(%rsi) 893e
#DEFINE mov____%r8,%r8 4d89c0
#DEFINE mov____%r8,0x8(%rbp) 4c8945
#DEFINE mov____%r9,%r9 4d89c9
#DEFINE mov____%r9,%rdi 4c89cf
#DEFINE mov____%r9,0x8(%rbp) 4c894d
#DEFINE mov____%rax,%rbx 4889c3
#DEFINE mov____%rax,%rcx 4889c1
#DEFINE mov____%rax,%rdx 4889c2
#DEFINE mov____%rax,%rsi 4889c6
#DEFINE mov____%rbp,%rcx 4889e9
#DEFINE mov____%rbp,%rdx 4889ea
#DEFINE mov____%rbp,%rsi 4889ee
#DEFINE mov____%rcx,%rcx 4889c9
#DEFINE mov____%rcx,%rdi 4889cf
#DEFINE mov____%rcx,%rdx 4889ca
#DEFINE mov____%rcx,%rsi 4889ce
#DEFINE mov____%rcx,0x8(%rbp) 48894d
#DEFINE mov____%rdi,%rdx 4889fa
#DEFINE mov____%rdi,%rsi 4889fe
#DEFINE mov____%rdx,%rcx 4889d1
#DEFINE mov____%rdx,%rdx 4889d2
#DEFINE mov____%rdx,%rsi 4889d6
#DEFINE mov____%rdx,0x8(%rbp) 488955
#DEFINE mov____%rsi,%rax 4889f0
#DEFINE mov____%rsi,%rcx 4889f1
#DEFINE mov____%rsi,%rdi 4889f7
#DEFINE mov____%rsi,%rdx 4889f2
#DEFINE mov____%rsi,%rsi 4889f6
#DEFINE mov____%rsi,0x32 48893425
#DEFINE mov____%rsi,0x8(%rbp) 488975
#DEFINE mov____%rsi,0x8(%rdi) 488977
#DEFINE mov____(%rdx),%edx 8b12
#DEFINE mov____(%rdx),%rdx 488b12
#DEFINE mov____(%rsi),%rsi 488b36
#DEFINE mov____0x32(%rbp),%rcx 488b8d
#DEFINE mov____0x32(%rbp),%rdx 488b95
#DEFINE mov____0x32(%rbp),%rsi 488bb5
#DEFINE mov____0x32,%rcx 488b0c25
#DEFINE mov____0x32,%rdx 488b1425
#DEFINE mov____0x32,%rsi 488b3425
#DEFINE mov____0x8(%rax),%rsi 488b70
#DEFINE mov____0x8(%rdi),%rbx 488b5f
#DEFINE movsbq_%cl,%rcx 480fbec9
#DEFINE movsbq_%dl,%rdx 480fbed2
#DEFINE movsbq_%sil,%rsi 480fbef6
#DEFINE movslq_%ecx,%rcx 4863c9
#DEFINE movslq_%edx,%rdx 4863d2
#DEFINE movslq_%esi,%rsi 4863f6
#DEFINE movswq_%si,%rsi 480fbff6
#DEFINE movzbq_%dl,%rdx 480fb6d2
#DEFINE movzbq_%sil,%rsi 480fb6f6
#DEFINE movzbq_(%rsi),%rsi 480fb636
#DEFINE movzlq_(%rdx),%rdx 8b12
#DEFINE movzlq_(%rsi),%rsi 8b36
#DEFINE movzwq_(%rsi),%rsi 480fb736
#DEFINE mul____%rbx 48f7e3
#DEFINE mul____%rcx 48f7e1
#DEFINE mul____%rdx 48f7e2
#DEFINE mul____%rsi 48f7e6
#DEFINE or_____%rdx,%rsi 4809d6
#DEFINE or_____%rsi,%rdi 4809f7
#DEFINE pop____%rcx 59
#DEFINE pop____%rsi 5e
#DEFINE push___%rcx 51
#DEFINE push___%rsi 56
#DEFINE shl____$i8,%rsi 48c1e6
#DEFINE shl____%cl,%rsi 48d3e6
#DEFINE sub____$i32,%rsi 4881ee
#DEFINE sub____%rcx,%rdx 4829ca
#DEFINE sub____%rdx,%rsi 4829d6
#DEFINE sub____%rsi,%rdi 4829f7
#DEFINE test___%rdx,%rdx 4885d2
#DEFINE xchg___%rdi,%rsi 4887fe
#DEFINE xchg___%rdx,%rcx 4887d1
#DEFINE xchg___%rsi,%rdx 4887f2

DEFINE SYS_write 01000000
DEFINE SYS_exit  3c000000
