Coder Social home page Coder Social logo

akshat-oke / p8086 Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 419 KB

An 8086 pre-processor : language like C/Java which compiles to 8086 instructions.

Home Page: https://akshat-oke.github.io/p8086/docs/

JavaScript 50.84% Assembly 1.14% Parrot 0.31% HTML 19.18% CSS 28.53%
8086 compiler ohmjs javascript-es6

p8086's Introduction

icon
home-fill

Welcome

p8086 is the pre-processor for 8086. You can think of it as a new language which is similar to a lot of high level languages like C/C++/Java.

What does it do?

Your code written in p8086 will "compile" to standard 8086 instructions like MOV or JMP. You can then pass on this code to the assembler and see how it executes it calmly and precisely as you will hope.

Installation and usage

You can use p8086 online at https://akshat-oke.github.io/p8086/src/ Alternatively, you can install p8086 as a CLI through npm.

$ npm i --global p8086

To compile your code saved at pc\folder\code.p86, cd into the folder and run:

pc\folder> p8086 code.p86

This will write the compiled code to pc\folder\code.asm.

Don't use .asm as an extension for your source code file since it will be overwritten by the compiler.

Example

Here is a quick example of a code in p8086 to determine whether a number is even or odd.

/* A sample program in p8086
*/
db num = 24; //input
if(num%2 == 0){
  print "Even"; // very simple
} else {
  print "Odd";
}
end; // see 'Statements' for more info

This code will compile to the following 8086 Assembly Language:

.MODEL SMALL
.STACK 200H
.DATA
num DW 24
str1 DB "Even$"
str2 DB "Odd$".CODE
;if (num%2 == 0)
;num%2 == 0
;num % 2
PUSH num
PUSH 2
POP BX
POP AX
PUSH DX
MOV DX, 0
DIV BX
MOV AX, DX
POP DX
PUSH AX
PUSH 0
POP AX
POP BX
CMP BX, AX
JNZ ifElse1
PUSH OFFSET str1
POP DX
MOV AH, 09
INT 21H
JMP ifElse1out
ifElse1:
PUSH OFFSET str2
POP DX
MOV AH, 09
INT 21H
ifElse1out:
.EXIT
END

Woah! That's a lot of assembly for just 7 lines of p8086! This is because of...

Unobtrusiveness

p8086 is designed to be unobtrusive with any other statements in the code.

Every statement is thus independent of others.

In the above code, since the print statement needed to use registers DX and AX, it saves them to the stack and restores them afterwards.

Do tell me if there is a simpler way of doing this!

Any valid 8086 instruction is also a valid p8086 instruction! This means you can use p8086 for just a small part of your original 8086 program, or vice versa!

Let's go!

Ready to use p8086? Head on to learn the syntax from the next page right away!

p8086's People

Contributors

akshat-oke avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.