Skip to content

Instantly share code, notes, and snippets.

@ndnenkov
Created January 10, 2014 22:56
Show Gist options
  • Save ndnenkov/8364314 to your computer and use it in GitHub Desktop.
Save ndnenkov/8364314 to your computer and use it in GitHub Desktop.
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