Created
January 10, 2014 22:56
-
-
Save ndnenkov/8364314 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe "Asm" do | |
it "runs an empty program" do | |
Asm.asm do | |
end.should eq [0, 0, 0, 0] | |
end | |
it "divides positive numbers" do | |
Asm.asm do | |
mov ax, 37 | |
mov bx, 6 | |
mov dx, ax | |
label looper | |
inc cx | |
dec dx, bx | |
cmp dx, bx | |
jg looper | |
end.should eq [37, 6, 37 / 6, 37 % 6] | |
end | |
it "finds modulus" do | |
Asm.asm do | |
mov ax, 3 | |
mov bx, 0 | |
mov cx, -3 | |
cmp ax, 0 | |
jg ax_positive | |
dec dx, ax | |
mov ax, dx | |
label ax_positive | |
cmp bx, 0 | |
jg bx_positive | |
mov dx, 0 | |
dec dx, bx | |
mov bx, dx | |
label bx_positive | |
cmp cx, 0 | |
jg cx_positive | |
mov dx, 0 | |
dec dx, cx | |
mov cx, dx | |
label cx_positive | |
mov dx, 0 | |
end.should eq [3.abs, 0.abs, -3.abs, 0] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment