Skip to content
Snippets Groups Projects
Commit 6fc2e076 authored by Ashwaq Abdullah M Alsaqer's avatar Ashwaq Abdullah M Alsaqer
Browse files

All examples related to errors

parent 40f15638
Branches
No related tags found
No related merge requests found
;; DIV statement to test for zero divide
MOV R3 10 ; N = 10
MOV R2 0 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
;; invalid instruction test for length of the inputs
MOV R3 10 ; N = 10
MOV R2 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
;; invalid instruction test for length of the inputs
MOV R3 10
MOV R2 10 10 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
;; Invalid instruction not in the list
MVo R3 10 ; N = 10
MOV R2 0 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
;; JMP with jumping with invalid register value
MOV R3 -100
MOV R2 10
MOV R4 100
DIV R4 R3 R2
JMP -10000
RET R4
\ No newline at end of file
;; JZ with jumping with invalid register value
MOV R3 10
MOV R2 10
MOV R4 100
SUB R4 R3 R2
JZ R4 10000
RET R4
\ No newline at end of file
;; Statement with multiple RET statements
;; array program. Fills an array with the values 0 ... N-1
;; and then interates through the array, summing its elements
;; global constants:
;; R3 holds 'N', the length of the array
;; R2 holds 1, the increment value used below
MOV R3 10 ; N = 10
MOV R2 1 ;
;; create the array
;; local variables
;; R1 holds 'i', which is a counter from 0 .. N-1
;; R0 holds 'p', the address of the array's ith element
MOV R1 0 ; i = 0;
MOV R0 100
SUB R4 R3 R1 ; while(i != N)
JZ R4 5 ; {
STR R0 0 R1 ; *p = i;
ADD R1 R1 R2 ; i = i + 1;
ADD R0 R0 R2 ; p = p + 1;
JMP -5 ; }
;; sum up the array
;; local variables
;; R1 holds 'i', which is a counter from 0 .. N-1
;; R0 holds 'p', the address of the array's ith element
;; R5 holds 'sum', which always holds the sum of the array's first i elements
MOV R1 0 ; i = 0;
MOV R0 100
MOV R5 0 ; sum = 0;
RET R5
SUB R4 R3 R1 ; while(i != N)
JZ R4 6 ; {
LDR R4 R0 0 ;
ADD R5 R5 R4 ; sum = sum + *p;
ADD R0 R0 R2 ; p = p + 1;
ADD R1 R1 R2 ; i = i + 1;
JMP -6 ; }
RET R5 ; return sum;
;; No Return value
MOV R3 10
MOV R2 10
MOV R4 100
DIV R4 R3 R2
\ No newline at end of file
;; Register value not in range of 0...31
MOV R33 10 ; N = 10
MOV R2 0 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
;; Register value not in range of 0...31
MOV R-2 10 ; N = 10
MOV R2 0 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
;; JMP with jumping with invalid register value
MOV R3 -100
MOV R2 10
MOV R4 100
DIV R4 R3 R2
JMP 1
ADD R4 R3 R4
MOV R5 100
RET R5
\ No newline at end of file
;; value not in range of -65536.... 65535
MOV R3 70000 ; N = 10
MOV R2 0 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
;; value not in range of -65536.... 65535
MOV R3 -70000 ; N = 10
MOV R2 0 ;
MOV R4 100
DIV R4 R3 R2
RET R4
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment