|
![]() |
Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming | |
Solved: 8051 Assembly Coding
|
||
![]() |
|
|
LinkBack | Thread Tools |
|
|
#1 (permalink) | ||||||||||||
|
110100001101001111000
|
I'm trying to implement an 8051 subroutine that compares 2 values (unsigned) and places the larger value in the accumulator. I'm trying to do so by using the stack pointer, but I can't seem to get the stupid thing going. This is my basic program:
Code:
CSEG AT 0x0000
LJMP start
RSEG assn2
START:
MOV SP,#0x30 ; initialize stack pointer
MOV 0x30,#0x00 ; move value into local memory
PUSH 0x30 ; push memory onto stack
MOV 0x38,#0xff ; move value into local memory
PUSH 0x38 ; push memory onto stack
LCALL findMAX ; call function
LJMP WAIT
findMAX:
POP 0x50 ; store half of LCALL return address
POP 0x58 ; store half of LCALL return address
POP 0x38 ; Pop op1 to memory
POP 0x30 ; Pop op2 to memory
MOV A,0x38 ; move value into A
SUBB A,0x30 ; subtract both values
JNC SKIP ; if no carry, A is larger
XCH A,0x30 ; if carry, switch A with other value
LJMP DONE
SKIP:
MOV A,0x38 ; move larger value to A
SJMP DONE
DONE:
PUSH 0x58 ; restore half of LCALL return address
PUSH 0x50 ; restore half of LCALL return address
RET ; return to function
WAIT:
SJMP WAIT
end
__________________
Last edited by C-bro : 03-20-07 at 05:00 PM. |
||||||||||||
|
|
|
|
#2 (permalink) | ||||||||||||
|
110100001101001111000
|
Nobody knows anything about assembly?
__________________
|
||||||||||||
|
|
|
|
#3 (permalink) | |||||||||||||
|
Intel Overclocker
|
Im scratchin my head at the moment,
__________________I didnt have Push and Pop on 68000CPU I will keep trying to figure it out! ![]() EDIT: MOV R0,0x30 are you moving the contents of R0 into memory @ 0x30 ? would it be the other way round? (Im NOT an Intel asm expert LOL!!)
Last edited by BugBash : 03-20-07 at 10:23 AM. |
|||||||||||||
|
|
|
|
|
#4 (permalink) | ||||||||||||
|
110100001101001111000
|
That MOV was moving the memory 0x30 into R0. That was just remnants of a trial and error. Instead of using the stack, I tried using R0 and R1 to store the values instead of storing the on the stack. It worked fine that way, so it's definitely a problem with how I'm using the stack. I'm going to see our TA today and hopefully he'll have some insight.
__________________
|
||||||||||||
|
|
|
|
#5 (permalink) | |||||||||||||
|
Apple Doesn't Love You
|
If you push 0x30 then 0x38 you have to pop 0x38 then 030 since stacks are FILO
The stack looks like this with both pushed top->0x38->0x30 With stacks you pop from the top
|
|||||||||||||
|
|
|
|
#6 (permalink) | ||||||||||||||
|
Turing Test is Overrated
|
I know the answer is pretty easy... just don't remember enough assembly... sorry
![]() If you ever have to do the 8-Queens or Tower of Hanoi problem, I still have the files saved from college days.
__________________
WANTED: Socket M Core/Core 2 CPU, SUGO-02 Black, quality 802.11b/g PCI Card To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it will work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single/Non-Modular Rail PSUs are NOT better than Multi-Rail/Modular Quote:
|
||||||||||||||
|
|
|
|
#7 (permalink) | |||||||||||||
|
Intel Overclocker
|
Cool!
__________________I didnt use the stack much at all in my asm days, mainly to store what was in the address and data registers when my program started and to put them back when my program exited. It was cool to see similar opcodes! mov -> move. (b/w/l) Byte,Word,Longword or Dword is it in x86? Good luck in your studies!
|
|||||||||||||
|
|
|
|
|
#8 (permalink) | ||||||||||||
|
110100001101001111000
|
Success!! I can't believe I did something so stupid.
LCALL findMAX The MAIN reason for using LCALL is that the address of that instruction gets stored, so when you RET from the function you're in the same place as when you called it. What was happening was that I pushed both values on stack, but as soon as I did LCALL, the address of that call went on the stack (since address is 16 bits, and stack is 8 bits wide, it essentially does 2 pushes). Long story short, I just popped off the 16 bit address, worked with my two operands, and push the address back on to return to my main function. Code:
findMAX:
POP 0x50 ; store half of LCALL return address
POP 0x58 ; store half of LCALL return address
POP 0x38 ; Pop op1 to memory
POP 0x30 ; Pop op2 to memory
MOV A,0x38 ; move value into A
SUBB A,0x30 ; subtract both values
JNC SKIP ; if no carry, A is larger
XCH A,0x30 ; if carry, switch A with other value
LJMP DONE
SKIP:
MOV A,0x38 ; move larger value to A
SJMP DONE
DONE:
PUSH 0x58 ; restore half of LCALL return address
PUSH 0x50 ; restore half of LCALL return address
RET ; return to function
__________________
|
||||||||||||
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|