boginw / js-y86-64 Goto Github PK
View Code? Open in Web Editor NEWThis project forked from xsznix/js-y86
y86-64 simulator and assembler written in Javascript.
Home Page: https://boginw.github.io/js-y86-64/
License: MIT License
This project forked from xsznix/js-y86
y86-64 simulator and assembler written in Javascript.
Home Page: https://boginw.github.io/js-y86-64/
License: MIT License
y64 code:
# Execution begins at address 0
.pos 0
irmovq stack, %rsp # Set up stack pointer
call main # Execute main program
halt # Terminate program
f0:
irmovq $0x10, %rax
ret
f1:
irmovq $0x11, %rax
ret
f2:
irmovq $0x12, %rax
ret
f3:
irmovq $0x13, %rax
ret
f4:
irmovq $0x14, %rax
ret
jtable:
.quad f0
.quad f1
.quad f2
.quad f3
.quad f4
jmp_to_n:
pushq %rdi
mrmovq -3(%rsp), %rbx # rbx = 8 * rdi
mrmovq jtable(%rbx), %rbx
irmovq 2, %r10
rmmovq %rbx, real_jmp(%r10) # *real_jmp = %rbx
real_jmp:
jmp jtable
main:
irmovq $0x2,%rdi
call jmp_to_n
ret
# Stack starts here and grows to lower addresses
.pos 0x200
stack:
According to the CS:APP book 3rd edition, section 3.6.1, it is stated "For the logical operations, such as XOR, the carry and overflow flags are set to zero". To my understanding, other than not having the carry flag, y86 should have the same behavior on condition codes as x86.
Currently, if you do something like an addq
that sets the overflow flag, the xorq
instruction does not clear it. This is an easy fix in the instr.js file, line 81, where you can first set OF to zero before going into the switch statement.
Here is an example of a .ys code that reflects the discrepancy with the book stated above:
irmovq scratch, %rax
rrmovq %rax, %rbx
rmmovq %rbx, 0x8(%rax)
irmovq 0x9, %rax
irmovq 0x7fffffffffffffff, %rbx
addq %rbx, %rax
xorq %rax, %rax
halt
scratch:
The description on wiki page says jge
"jumps to Dest if ~(SF^OF)
", but the following code has different behavior with this description.
irmovq $0x8000000000000000, %rcx
irmovq $0x2, %rdx
subq %rdx, %rcx
# SF=0, OF=1
jge B2
B1:
irmovq $0xab, %rax
halt
B2:
irmovq $0xcd, %rax
halt
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.