Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 03-19-07   #1 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default Solved: 8051 Assembly Coding

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
Edit: This is the corrected code for finding the max between two value stored in 0x30 and 0x38 in memory.

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N

Last edited by C-bro : 03-20-07 at 05:00 PM.
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Old 03-20-07   #2 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default

Nobody knows anything about assembly?

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Old 03-20-07   #3 (permalink)
Intel Overclocker
 
intel nvidia

Join Date: Apr 2006
Location: London
Posts: 645

Rep: 44 BugBash is acknowledged by some
Unique Rep: 41
Trader Rating: 0
Default

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!!)
__________________
System: My System
CPU
P4 2.66 @ 3.45
Motherboard
Abit IC7-G
Memory
2.5GB DDR400
Graphics Card
XFX 7800GS 256MB AGP
Hard Drive
WD5000YS(500GB)+320GB+40GB
Sound Card
SB Audigy 4
Power Supply
Tagan 480-U22
Case
Silverstone TJ-05
CPU cooling
Thermalrite XP-120
GPU cooling
Stock
OS
Windows XP SP2
Monitor
HP L2208w Optoma DX606

Last edited by BugBash : 03-20-07 at 10:23 AM.
BugBash is offline   Reply With Quote
Old 03-20-07   #4 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default

Quote:
Originally Posted by BugBash View Post
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!!)
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.

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Old 03-20-07   #5 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,975
Blog Entries: 1

Rep: 564 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 338
FAQs Submitted: 6
Trader Rating: 5
Default

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
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 03-20-07   #6 (permalink)
Turing Test is Overrated
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 24,173

Rep: 2803 DuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legend
Unique Rep: 1294
Folding Team Rank: 966
Trader Rating: 34
Default

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:
catmmm: no wifi? gay
e_dogg: I use both wired and wireless in my house. Does that make me bi?

System: My "DF-DIE" Replacement
CPU
Q6600 (3.7GHz)
Motherboard
Asus P5E X38 (MF1208 BIOS)
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
8800GT (729/1836/2088)
Hard Drive
PERC 5/i: 3xRAID0 Raptor 74GB + 7200.10 250GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
MCW60 + Iandh HS + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline I fold for Overclock.net Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 03-20-07   #7 (permalink)
Intel Overclocker
 
intel nvidia

Join Date: Apr 2006
Location: London
Posts: 645

Rep: 44 BugBash is acknowledged by some
Unique Rep: 41
Trader Rating: 0
Default

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!
__________________
System: My System
CPU
P4 2.66 @ 3.45
Motherboard
Abit IC7-G
Memory
2.5GB DDR400
Graphics Card
XFX 7800GS 256MB AGP
Hard Drive
WD5000YS(500GB)+320GB+40GB
Sound Card
SB Audigy 4
Power Supply
Tagan 480-U22
Case
Silverstone TJ-05
CPU cooling
Thermalrite XP-120
GPU cooling
Stock
OS
Windows XP SP2
Monitor
HP L2208w Optoma DX606
BugBash is offline   Reply With Quote
Old 03-20-07   #8 (permalink)
110100001101001111000
 
C-bro's Avatar
 
intel nvidia

Join Date: Jan 2006
Location: Hamilton, ON
Posts: 1,832

Rep: 283 C-bro is a proven memberC-bro is a proven memberC-bro is a proven member
Unique Rep: 215
FAQs Submitted: 6
Folding Team Rank: 237
Hardware Reviews: 9
Trader Rating: 1
Default

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

System: RAID0R
CPU
Intel E2180 3.33GHz
Motherboard
Asus P5K-E/WIFI-AP vMod
Memory
2GB Kingmax DDR2-1066
Graphics Card
EVGA 8800GT
Hard Drive
2x250GB WD+500GB 7200.11
Sound Card
SB Audigy 2
Power Supply
Corsair CMPSU-550VX
CPU cooling
Arctic Cooling Freezer 7 Pro
GPU cooling
Zalman VF900-Cu
OS
Windows Vista Business 32-Bit
Monitor
HP F2105 21" & Samsung 712N
C-bro is offline I fold for Overclock.net Overclocked Account C-bro's Gallery   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 02:01 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.26277 seconds with 8 queries