Jump to content

Neeed help with Assembly program (ARM)


Recommended Posts

Posted

Ok so my assignment is to make a calculator, that given input from a textfile, will determine what I am to calculate. I am then to make a program that decodes the instruction, and runs the proper calculation according to the input. I am not having trouble loading the input or anything, I am having a problem where, every one of my functions runs regardless. So when I try to add something, it gets added, subtracted, and multiplied, etc. 

 

Here is my current code:

.globl _start

@ error code values
@ you can easily load these like: mov r0,#ERR_OP_UNDEFINED
.equ ERR_NONE, 0x00000000
.equ ERR_OP_UNDEFINED, 0x00000001
.equ ERR_OP_OVERFLOW, 0x00000002
.equ ERR_OP_DIV_BY_ZERO, 0x00000003

_start:
	@ set up r0 with _operandA
        @ for example:
	@ldr	r3,=_operandA
	@ldr	r0,[r3]		@ r0 := mem[r3]
        
	ldr	r3,=_operandA                                   
	ldr	r0,[r3]		@ r0 := mem[r3]=operandA     r0 contains the first variable
	ldr	r3,=_operandB
	ldr	r1,[r3]		@ r1 := mem[r3]=operandB     r1 contains the second
	ldr	r3,=_operation
	ldr	r2,[r3]		@ r2 :=mem[r3]=operation     r2 contains the number corresponding to      
                                                             the operation I am supposed to execute
                                                             all of these load properly

        @ modify appropriately based on input arguments (e.g., decode _operation)

@These compare statements are what im not quite understanding correctly...
@Why the hell do they all execute, when only one of them should...
@note I am requred to use bl
	cmpeq	r2,#1
	mov	r8,#5		@test this compare
	bl	executeAdd

	cmpeq	r2, #2
	mov	r9,#6		@test this compare
	bl	executeSubtract

	cmpeq	r2, #3
	mov	r10,#7		@test this compare
	bl	executeMultiply

	cmpeq	r2, #4
	mov	r11,#8		@test this compare
	bl	executeDivide

	cmpeq	r2, #5
	mov	r12,#9		@test this compare
	bl	executeNegate



@the instructor added this here and it is required to be here
iloop:	b iloop			@ leave this infinite loop at the end of your program (needed for grading)
	




@ write execution procedures here:
@ I started by writing the first 3
@ Note I am required to use bx lr at the end of the procedure
executeAdd:
	cmp	r2,#1
	mov	r4,#0
	add	r4,r0,r1	@ r4 := r0+r1
	mov	r2,#99
	bx	lr

executeSubtract:
	mov	r5,#0
	sub	r5,r0,r1	@ r5 := r0-r1
	mov	r2,#99
	bx	lr


executeMultiply:
	mov	r6,#8
	mul	r6,r0,r1	@r6 := r0*r1
	mov	r2,#99
	bx	lr

executeDivide:
	mov	r2,#99
	bx	lr
	
executeNegate:
	mov	r2,#99
	bx	lr


stop:
	end


@ write error handling procedures here:
@ NOTE: you'll want to use the stack here, since these handlers may be called from other functions (e.g., handleDivByZero will be called by executeDivide)

handleUndefined:
	bx	lr

handleOverflow:
	bx	lr

handleDivByZero:
	bx	lr

And here is my resulting output to the registers after I am finished:

 

http://gyazo.com/3d168de21ddb6a6b9171d70261810303

 

I placed 5,6,7,8 in registers 8,9,10,11,12 in order to test the compare statement, and they all execute..

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...