6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 15, 2024 9:26 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Help with code anyone??
PostPosted: Wed Jun 01, 2005 2:19 pm 
Offline

Joined: Wed Jun 01, 2005 2:09 pm
Posts: 1
Hello I am doing a computer course at college and the module for this term is Machine code in which we are using 6502.
I have been given an assignment and am having trouble with the second part of the program which needs me to display the answer of a multiplication sum to the i/o screen.
I have completed Program 1 but I was hoping that someone could help me out here with Program 2 as I have spent a long time trying to work it out and just can’t seem to work out how to do it. Any help will be much appreciated.
I am using Michal Kowlalski’s 6502 simulator v.1.2.5

Here is the code I have written for Program 1 :-

.ORG $0200



LDA #$03
STA NUM1
LDA #$05
STA NUM2

CLC

LDX #$00

CPX NUM1
BEQ End
CPX NUM2
BEQ End

Loop: LDA RES
ADC NUM2
STA RES

INX

CPX NUM1
BNE Loop

End:
BRK



NUM1: .DB $00
NUM2: .DB $00
RES: .DB $00


Here is the Assignment brief :-


Program 1 – A program that multiplies two numbers together, and stores the result in memory. The program only has to support numbers that add up to 255.

Program 2 – Extend Program 1 in order to support the displaying of the results to the ASCII Terminal screen. This program only has to consider supporting results that are up to a value of 9 (i.e. the program need only to display results of a single character).


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Jun 02, 2005 8:13 am 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
As you only have to support numbers upto 9 its rather easy. Convert your number to an ASCII character by adding $30 (ASCII for '0') and then store it in the memory location that the simulator uses for character output.

If you want to support bigger numbers then you need to convert the binary value into a series of decimal values representing 100's, 10's and ones. There are several techniques for this: iteratively subtracting 100's, then 10's until just 1's are left; dividing by ten to get the last digit as the remainder; converting from binary to BCD the printing the nybbles.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 2 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: