File talk:Motorola 6800 Assembly Language.png
This file does not require a rating on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||
|
Untitled
[edit]
Hi I'm trying to print prime numbers from number1 and number2 Program gives output always from 2 till number2 istead of number1 If the first number is greater than the second it still shows 2 to number 2 instead of number 1 to number 2 .data
menu: .ascii "\n" .ascii "1, Enter Number 1\n" .ascii "2, Enter Number 2\n" .ascii "3, Display prime numbers between num1 and num2\n" .ascii "4, Quit\n" .ascii "\n" .ascii "Please enter menu option : " .asciiz ""
str.first: .asciiz "\nEnter first number :\t" str.second: .asciiz "\n Enter Second number :\t" str.combine: .asciiz " and " str.space: .asciiz " \t " str.newline: .asciiz " \n " str.prime: .asciiz " \n The prime numbers of : "
i: .word 2 p: .word 0 k: .word 2 c: .word 1
.text
addi $s1,$zero, 2 # default Value for num1 addi $s2,$zero, 8 # default Value for num2
printMenu: # Label so we can jump/branch back here la $a0, menu #set $a0 to label menu 's address addi $v0, $zero, 4 syscall
addi $v0, $zero, 5 syscall
add $s3,$zero, $v0
beq $s3,1,opt1 beq $s3,2 opt2 beq $s3,3,opt3 beq $s3,4,quit
j printMenu opt1:
addi $v0, $zero, 4 la $a0, str.first #set labels address into $a0 syscall #Displays Enter first number from $a0 addi $v0, $zero, 5 #Reads input from keyboard and stores in $v0 syscall addi $s1, $v0,0 # set FIRST NUMBER(s1) to user enter input(v0) j printMenu # jump back and print menu again opt2:
addi $v0, $zero, 4 la $a0, str.second #set labels address into $a0 syscall #Displays Enter Second number from $a0 addi $v0, $zero, 5 #Reads input from keyboard and stores in $v0 syscall addi $s2, $v0,0 # set SECOND NUMBER(s2) to user enter input(v0) j printMenu
opt3: main: li $v0, 4 # display message to user la $a0, str.prime #load address of the label in $a0 syscall #Display the string 'The prime numbers of : ' li $v0,1 move $a0,$s1 #Entered first number moved to $a0 syscall #Display the first number addi $v0, $zero, 4 la $a0, str.combine #load address of the label in $a0 syscall #'and' will be displayed in between first and the second number li $v0,1 move $a0,$s2 #Entered second number moved to $a0 from $s2 syscall #Display the second number addi $v0, $zero, 4 la $a0, str.newline #load address of the label in $a0 syscall
move $t0,$s1 #move contents of $s1 to $t0 move $t7,$s2 #move contents of $s2 to $t7 li $v0, 4 la $a0, str.space #load address of the label in $a0 syscall # call operating sys to leave gap after printing number
lw $t1, i # $t1 = i lw $t2, k # $t2 = k lw $t3, p # $t3 = p lw $t5, c # $t5 = c lw $t6, d # $t6 = d blt $t7,$t1 L2 #Branch to statement at Label L2 if $t7 is less than $t1 li $v0, 1 # print integer function call 1 move $a0, $t1 #move contents of $t1 is moved to $a0 syscall # integer to print call operating sys li $v0, 4 la $a0, str.space #load address of the label in $a0 syscall # call operating sys to print space or gap
L2: move $t3, $zero # Inner loop L1: remu $t4, $t1, $t2 # remainder set to $t4(remainder of $t1 divided by $t3) bne $t4, $zero, I move $t3, $t5 I: add $t2, $t2, $t5 # increment k blt $t2, $t1 L1 bne $t3, $zero, P li $v0, 1 # print integer function call 1 move $a0, $t1 # move contents of $t1 to $a0 syscall #prints the integer
move $t2, $t6 #move contents $t6 to $t2 bgt $t1, $t7, E #branch to statements at label if $t1 is greater than $t7 j L2
opt4: quit: — Preceding unsigned comment added by 86.15.114.95 (talk • contribs) 11:55, 30 December 2014 |