6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 6:00 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: PLEASE HELP ME
PostPosted: Tue Mar 21, 2006 4:15 am 
Offline

Joined: Tue Mar 21, 2006 4:12 am
Posts: 1
I need a program for 6502 that divides a number, that was enter with the keyboard, by 2. And present the result in the I/O window.

Please somebody help me.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Mar 21, 2006 4:35 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8546
Location: Southern California
How the number is entered and output will depend a lot on the hardware. How it is represented in memory depends on what other software you are using. If the number is represented in memory as a non-negative hexadecimal integer, the job is as simple as using LSR on the high byte, and ROR on subsequent bytes until the entire number is shifted to the right by one bit position. If it's only a two-byte (ie, 16-bit) number, it only requires the two instructions:
Code:
        LSR  <address of high byte>
        ROR  <address of low byte address>
Very simple. The remainder from the division is in the carry flag.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Mar 22, 2006 6:59 pm 
Offline

Joined: Tue Dec 30, 2003 10:35 am
Posts: 42
This is obviously a homework question. Anyway, a simple solution is to output the number in base 2 (binary) but leave off the last bit (or to be accurate, put a decimal point before the last bit). The teacher might not like it, but it is dividing the number by two.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Mar 22, 2006 8:20 pm 
Offline

Joined: Sun Feb 05, 2006 1:20 am
Posts: 21
Location: The Netherlands
blargg wrote:
<snip> ... put a decimal point before the last bit). The teacher might not like it, but it is dividing the number by two.

Meaning, redefine the format. Teachers generally don't like like "solutions" that involve redefining things ;)

Obviously, Juan, your question is not specific enough.

_________________
I trust my somewhat flawed English is comprehensible to all.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: