Browse Source

Bugfix OP & glitch runner

Yann Weber 5 years ago
parent
commit
38ca6f22cf
1 changed files with 54 additions and 52 deletions
  1. 54
    52
      yaglitch.asm

+ 54
- 52
yaglitch.asm View File

@@ -266,6 +266,7 @@ parse:
266 266
 		stosq
267 267
 		xor rax, rax
268 268
 		xchg rax, rdx
269
+		shl rax, 32
269 270
 		stosq
270 271
 		pop rax
271 272
 		.match_op:
@@ -320,11 +321,12 @@ stack_init:
320 321
 	mov rcx, STACK_SZ
321 322
 	mov rdi, stack_buff
322 323
 	xor rax, rax
323
-	mov [tosp], rax
324 324
 	mov [t], eax
325 325
 	.loop_buff_init:
326 326
 		stosd
327 327
 		loop .loop_buff_init
328
+	mov al, 7 * 4
329
+	mov [tosp], al
328 330
 
329 331
 sdl_init:
330 332
 	mov rdi, 0x0000FFFF
@@ -562,29 +564,44 @@ run_glitch:
562 564
 		lodsq
563 565
 		mov rdi, rax
564 566
 		pop rax
567
+		push rsi
565 568
 		call rax
569
+		pop rsi
570
+		jmp .loop
566 571
 	.end_glitch:
567 572
 	xor rbx, rbx
568 573
 	mov bl, [tosp]
569 574
 	lea rdi, [stack_buff + rbx]
570 575
 	mov eax, [rdi]
571
-	push rax
572
-	mov rdi, rax
573
-	mov rsi, 1
574
-	call print_hnum
575
-	pop rax
576
+; DEBUG
577
+	;push rax
578
+	;xor rdi, rdi
579
+	;mov rdi, rax
580
+	;mov rsi, 1
581
+	;call print_hnum
582
+	;mov rax, " "
583
+	;push rax
584
+	;mov rax, 1
585
+	;mov rdi, 1
586
+	;mov rsi, rsp
587
+	;mov rdx, 1
588
+	;syscall
589
+	;pop rax
590
+	;pop rax
591
+; /DEBUG
576 592
 	ret
577 593
 
578 594
 OP:
579 595
 	.numeric:
580 596
 		; rdi contain the number
597
+		shr rdi, 32
581 598
 	._push:
582 599
 		; push rdi (edi) on stack_buff
583 600
 		mov eax, edi
584 601
 		xor rbx, rbx
585 602
 		mov bl, [tosp]
586
-		inc bl
587
-		cmp bl, 8
603
+		add bl, 4
604
+		cmp bl, 8 * 4
588 605
 		jl .go_push
589 606
 		mov bl, 0
590 607
 		.go_push:
@@ -598,21 +615,21 @@ OP:
598 615
 		; pop eax from stack_buff
599 616
 		xor rbx, rbx
600 617
 		mov bl, [tosp]
618
+		lea rsi, [stack_buff+rbx]
619
+		xor rax, rax
620
+		lodsd
601 621
 		test bl, bl
602 622
 		jz .pop_no_dec
603
-		dec bl
604
-		jmp .go_pop
623
+		sub bl, 4
624
+		jmp .pop_end
605 625
 		.pop_no_dec:
606
-			mov bl, 7
607
-		.go_pop:
626
+			mov bl, 7 * 4
627
+		.pop_end:
608 628
 			mov [tosp], bl
609
-			lea rsi, [stack_buff+rbx]
610
-			lodsd
611 629
 		ret
612 630
 
613 631
 
614 632
 	.t: ; push t on the stack
615
-		xor rdi, rdi
616 633
 		mov edi, [t]
617 634
 		call ._push
618 635
 		ret
@@ -636,50 +653,40 @@ OP:
636 653
 		popf
637 654
 		ret
638 655
 	.mul:
639
-		call OP._pop
640
-		mov ebx, eax
641
-		call OP._pop
656
+		call .prep_2arg
642 657
 		mul ebx
643 658
 		mov edi, eax
644 659
 		call OP._push
645 660
 		ret
646 661
 	.div:
647
-		call OP._pop
648
-		mov ebx, eax
649
-		call OP._pop
662
+		call .prep_2arg
650 663
 		div ebx
651 664
 		mov edi, eax
652 665
 		call OP._push
653 666
 		ret
654 667
 	.add:
655
-		call OP._pop
656
-		mov ebx, eax
657
-		call OP._pop
668
+		call .prep_2arg
658 669
 		add eax, ebx
659 670
 		mov edi, eax
660 671
 		call OP._push
661 672
 		ret
662 673
 	.sub:
663
-		call OP._pop
664
-		mov ebx, eax
665
-		call OP._pop
674
+		call .prep_2arg
666 675
 		sub eax, ebx
667 676
 		mov edi, eax
668 677
 		call OP._push
669 678
 		ret
670 679
 	.mod:
671
-		call OP._pop
672
-		mov ebx, eax
673
-		call OP._pop
680
+		call .prep_2arg
674 681
 		div ebx
675 682
 		mov edi, edx
676 683
 		call OP._push
677 684
 		ret
678 685
 	.lshift:
679
-		xor rcx, rcx
680 686
 		call OP._pop
681
-		mov ecx, eax
687
+		push rax
682 688
 		call OP._pop
689
+		pop rcx
683 690
 		.lshift_loop:
684 691
 			shl eax, 1
685 692
 			loop .lshift_loop
@@ -687,10 +694,10 @@ OP:
687 694
 		call OP._push
688 695
 		ret
689 696
 	.rshift:
690
-		xor rcx, rcx
691 697
 		call OP._pop
692
-		mov ecx, eax
698
+		push rax
693 699
 		call OP._pop
700
+		pop rcx
694 701
 		.rshift_loop:
695 702
 			shr eax, 1
696 703
 			loop .rshift_loop
@@ -698,25 +705,19 @@ OP:
698 705
 		call OP._push
699 706
 		ret
700 707
 	.and:
701
-		call OP._pop
702
-		mov ebx, eax
703
-		call OP._pop
708
+		call .prep_2arg
704 709
 		and eax, ebx
705 710
 		mov edi, eax
706 711
 		call OP._push
707 712
 		ret
708 713
 	.or:
709
-		call OP._pop
710
-		mov ebx, eax
711
-		call OP._pop
714
+		call .prep_2arg
712 715
 		or eax, ebx
713 716
 		mov edi, eax
714 717
 		call OP._push
715 718
 		ret
716 719
 	.xor:
717
-		call OP._pop
718
-		mov ebx, eax
719
-		call OP._pop
720
+		call .prep_2arg
720 721
 		xor eax, ebx
721 722
 		mov edi, eax
722 723
 		call OP._push
@@ -760,9 +761,7 @@ OP:
760 761
 		call OP._push
761 762
 		ret
762 763
 	.lt:
763
-		call OP._pop
764
-		mov ebx, eax
765
-		call OP._pop
764
+		call .prep_2arg
766 765
 		xor rdi, rdi
767 766
 		cmp eax, ebx
768 767
 		jge .lt_false
@@ -771,9 +770,7 @@ OP:
771 770
 		call OP._push
772 771
 		ret
773 772
 	.gt:
774
-		call OP._pop
775
-		mov ebx, eax
776
-		call OP._pop
773
+		call .prep_2arg
777 774
 		xor rdi, rdi
778 775
 		cmp eax, ebx
779 776
 		jle .gt_false
@@ -782,9 +779,7 @@ OP:
782 779
 		call OP._push
783 780
 		ret
784 781
 	.eq:
785
-		call OP._pop
786
-		mov ebx, eax
787
-		call OP._pop
782
+		call .prep_2arg
788 783
 		xor rdi, rdi
789 784
 		cmp eax, ebx
790 785
 		jne .eq_false
@@ -793,3 +788,10 @@ OP:
793 788
 		call OP._push
794 789
 		ret
795 790
 
791
+	.prep_2arg:
792
+		; utils that pop both arguments V1 in eax, V2 in ebx
793
+		call OP._pop
794
+		push rax
795
+		call OP._pop
796
+		pop rbx
797
+		ret

Loading…
Cancel
Save