That's not a question. It's a statement. If the question is "how", the answer would be, "do all the things the rest of the students are expected to do".
If you want anyone here to attempt to read your code, you need to at least comment each line. You should also explain your approach.
I see RET instructions. There are no function calls in the C source code, so that is a mistake right there.
Another issue. The AVR is an 8 bit processor, an int is 16 bits. You haven't addressed that in your code.
I think the real question is: will someone do my Uni assignment for me?
What I mean is that when I press the button my LCD freezes if I'm using the assembly code for the if statement and I don't really understand why. I just wanted to increment the value of the variable then return to the C program and if the value went past 4 I needed it to be set back to 0 so that it doesn't mess my main program. I don't understand what exactly is wrong about what I wrote in my code
I identified two major issues for you, and you haven't responded at all. That's not a good sign.
Actually, three, because you seriously need to document what you're doing...
if(digitalRead(btnChange) == HIGH) {
asm(
"start: \n"
//"SBIS 0x09, 1 \n"
"CPI %0, 5 \n" // compare variable with 5
"BREQ mid \n" //if it's equal to 5 jump to labe
"CPI %0, 4 \n"
"BREQ mid \n"
"INC %0 \n" //increment the variable
"CPI %0, 5 \n"
"BREQ mid \n" // if variable is equal to 5 go to label
"RET \n" //otherwise go back to C program
"mid: \n"
"DEC %0 \n" //decrement the value of the variable
"CPI %0, 0 \n"
"BREQ end \n" //if value reaches 0 go to label
"RJMP mid \n" // otherwise keep on decrementing value
"end: \n"
"RET" //return to C program
: : "r" (slot)
);
}
So do you mean that I don't need RET because it's inline assembly? With ret I only wanted the programm to continue without paying attention to the assembly part
Translation: I have absolutely no clue what I'm doing, so I'll guess, be wrong, but have kind people on a forum fix it for me.
You haven't commented your code yet....
wait but I did add comments to the code
Okay. When you make updates, don't edit previous messages. It creates confusion about the replies.
Again, you have been asked to write inline code, not a function. And, at a glance, I don't see you handling the two bytes that an int would require.
I thought that I only need to put the least significant bit and most significant bit in registers only if I'm actively using the registers for something. I don't know the location where the variable is located to do that and I how would I even get acces to the variable in the other parts of my program if I defined it in registers?
Well, I'm sure that is all in the course materials that were handed out. That, or covered in previous assignments...
...by storing it in the RAM location assigned to that variable.
Why not submit the code you have, along with the rest of the assignment? It definitely is assembly code!
I doubt anyone will look carefully at it, but if they do, they might not realize or care that it doesn't do anything useful.
The C code doesnât match what I make of the comments in your assembly language version.
Lemme read both againâŚ
Yes, this
RJMP mid \n" // otherwise keep on decrementing value
seems to be a loop of some kind, no loop in any C version youâve posted.
a7
Wow dude, I am amazed that you two both without any basis or without knowing anything about what I need to do assumed that 1) I want you to do my homework for me 2) I have course material and previous assignments i can use to solve my problem 3) the rest of my code is in assembly. Never did I even imply something like this
Truly amazing , no idea what happened to you guys this morning to react like this(maybe the fact that I sent screenshots and expected everyone to know what I'm trying to do as I assumed that an if statement is very easy to do which I was definetely wrong about after trying to do so for two days but guess what, I am not an assembly expert)
Believe it or not the assignment was to write a part of my larger C program in assembly, any part that I wish to. In the end I just made some LEDS blink and incremented a variable, and both of these written in assembly are enough. But you definetely know my situation better than I do, so I really apreciate that you took your time to show some elitism and make assumptions for no reason at all. Anything like "you need to look up this specific topic because judging your code you have no understanding of it" would have helped a lot
Like you really believe the rest of my program is in assembly after seeing how I'm confused even about the use of registers like what???
Maybe next time get off your high horse instead of whatever this whole thread was
You could spend some time actually learning something about assembly coding, and just get the job done, as your instructors presumably expect you to do.
Instead, you flail around, posting nonsensical attempts, then ask for advice.
There is no reason to take anything you say very seriously, so, good luck with your Uni assignment!
Well that's exactly what I was doing, but you didn't even bother to take a look at those screenshots I posted. Imagine getting offended for some reason by a random guy on the internet not knowing assembly and asking for help. Literally all you wrote on this thread was making assumptions and saying that I want you to do my work multiple times. Like if that's your perspective don't bother answering and if you do I don't need you saying the same " actual question : "can someone do my assignment?" just written in a different way, like I understood your comment that doesn't add anything the first time. And for some reason you keep returning to this thread, if you think there's no point why bother answering. You did bother because this post made you so mad that you needed to leash out your frustrations but whatever, the assignment is done anyways but just not the way I wanted at first
Au contraire, I contributed (at least 3) concrete suggestions. You appeared to either ignore or not understand them. Maybe you were referring to someone else.
Could be, considering that the forum guidelines specifically discourage that.