about summary refs log tree commit diff stats
path: root/020run.cc
Commit message (Expand)AuthorAgeFilesLines
* 4421Kartik Agaram2018-07-261-36/+7
* 4418Kartik Agaram2018-07-261-4/+4
* 4417Kartik Agaram2018-07-261-1/+1
* 4267Kartik Agaram2018-06-241-4/+0
* 4266 - space for alloc-id in heap allocationsKartik Agaram2018-06-241-1/+38
* 4258 - undo 4257Kartik Agaram2018-06-151-11/+3
* 4257 - abortive attempt at safe fat pointersKartik Agaram2018-06-151-3/+11
* 4243Kartik Agaram2018-05-121-1/+1
* 4204Kartik K. Agaram2018-02-151-1/+10
* 4149Kartik K. Agaram2017-12-071-1/+4
* 4147Kartik K. Agaram2017-12-071-2/+6
* 4140Kartik K. Agaram2017-12-051-1/+1
* 4139Kartik K. Agaram2017-12-051-7/+5
* 4116 - support calling continuations with argumentsKartik K. Agaram2017-11-061-0/+2
* 4104Kartik K. Agaram2017-11-031-2/+2
* 4089Kartik K. Agaram2017-10-221-5/+3
* 3987Kartik K. Agaram2017-09-011-1/+1
* 3966Kartik K. Agaram2017-07-091-1/+1
* 3965 - get rid of the teardown() functionKartik K. Agaram2017-07-091-2/+1
* 3906Kartik K. Agaram2017-06-101-0/+1
* 3888 - beginnings of a profilerKartik K. Agaram2017-05-281-21/+48
* 3887 - clean up early exits in interpreter loopKartik K. Agaram2017-05-281-10/+18
* 3877Kartik K. Agaram2017-05-261-3/+3
* 3872Kartik K. Agaram2017-05-201-0/+1
* 3841Kartik K. Agaram2017-04-271-3/+3
* 3821Kartik K. Agaram2017-04-131-0/+1
* 3819Kartik K. Agaram2017-04-131-2/+5
* 3814Kartik K. Agaram2017-04-061-0/+1
* 3811Kartik K. Agaram2017-04-041-1/+1
* 3758Kartik K. Agaram2017-03-061-0/+1
* 3756 - start of some improvements to the trace browserKartik K. Agaram2017-03-051-1/+1
* 3707Kartik K. Agaram2016-12-121-3/+9
* 3701Kartik K. Agaram2016-11-291-0/+1
* 3682Kartik K. Agaram2016-11-221-3/+5
* 3675Kartik K. Agaram2016-11-151-2/+2
* 3655Kartik K. Agaram2016-11-081-1/+1
* 3653Kartik K. Agaram2016-11-081-1/+4
* 3652Kartik K. Agaram2016-11-081-0/+10
* 3643Kartik K. Agaram2016-11-071-3/+3
* 3630 - generate trace for a single scenarioKartik K. Agaram2016-11-061-3/+3
* 3596Kartik K. Agaram2016-10-251-0/+3
* 3561Kartik K. Agaram2016-10-221-4/+4
* 3555Kartik K. Agaram2016-10-221-1/+1
* 3522Kartik K. Agaram2016-10-191-9/+9
* 3446Kartik K. Agaram2016-10-061-1/+3
* 3435Kartik K. Agaram2016-10-041-0/+3
* 3380Kartik K. Agaram2016-09-171-11/+11
* 3358Kartik K. Agaram2016-09-151-0/+4
* 3335Kartik K. Agaram2016-09-111-2/+6
* 3334Kartik K. Agaram2016-09-111-2/+1
span>`/index`: `1` (ecx) - `/disp32`: 4 bytes containing `1000` ## Putting it all together Here's an example showing these arguments at work: <img alt='apps/ex3.subx' src='html/ex3.png'> This program sums the first 10 natural numbers. By convention I use horizontal tabstops to help read instructions, dots to help follow the long lines, comments before groups of instructions to describe their high-level purpose, and comments at the end of complex instructions to state the low-level operation they perform. Numbers are always in hexadecimal (base 16) and must start with a digit ('0'..'9'); use the '0x' prefix when a number starts with a letter ('a'..'f'). I tend to also include it as a reminder when numbers look like decimal numbers. --- I recommend you order arguments consistently in your programs. SubX allows arguments in any order, but only because that's simplest to explain/implement. Switching order from instruction to instruction is likely to add to the reader's burden. Here's the order I've been using after opcodes: ``` |<--------- reg/mem --------->| |<- reg/mem? ->| /subop /mod /rm32 /base /index /scale /r32 /displacement /immediate ``` --- Try running this example now: ```sh $ ./bootstrap translate init.linux apps/ex3.subx -o apps/ex3 $ ./bootstrap run apps/ex3 $ echo $? 55 ``` If you're on Linux you can also run it natively: ```sh $ ./apps/ex3 $ echo $? 55 ``` These details should now be enough information for reading and modifying low-level SubX programs. ## Translating SubX programs This repo includes two translators for bare SubX. The first is [the bootstrap translator](bootstrap.md) implemented in C++. In addition, you can use SubX to translate itself. For example, running natively on Linux: ```sh # generate translator phases using the C++ translator $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/hex.subx -o hex $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/survey_elf.subx -o survey_elf $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/pack.subx -o pack $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/assort.subx -o assort $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/dquotes.subx -o dquotes $ ./bootstrap translate init.linux 0*.subx apps/subx-params.subx apps/tests.subx -o tests $ chmod +x hex survey_elf pack assort dquotes tests # use the generated translator phases to translate SubX programs $ cat init.linux apps/ex1.subx |./tests |./dquotes |./assort |./pack |./survey_elf |./hex > a.elf $ chmod +x a.elf $ ./a.elf $ echo $? 42 # or, automating the above steps $ ./translate_subx init.linux apps/ex1.subx $ ./a.elf $ echo $? 42 ``` Or, running in a VM on other platforms (much slower): ```sh $ ./translate_subx_emulated init.linux apps/ex1.subx # generates identical a.elf to above $ ./bootstrap run a.elf $ echo $? 42 ``` ## Resources - [Single-page cheatsheet for the x86 ISA](https://net.cs.uni-bonn.de/fileadmin/user_upload/plohmann/x86_opcode_structure_and_instruction_overview.pdf) (pdf; [cached local copy](https://github.com/akkartik/mu/blob/master/cheatsheet.pdf)) - [Concise reference for the x86 ISA](https://c9x.me/x86) - [Concise reference for the x86 ISA #2](http://ref.x86asm.net/coder32.html) - [Intel processor manual](http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf) (pdf)