6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 5:35 pm

All times are UTC




Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 11:54 am 
Offline

Joined: Mon May 21, 2018 8:39 am
Posts: 41
Quote:
....You need to be aware that every assembler has different syntax....


WHAT? WHY? 6502 Assembly is....6502 assembly!!!! Isn't it???

Oh come on now guys! What means that "different syntax"?

Is it a waste of time the books I'm reading?


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 12:12 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
It's true, but don't worry too much! For example, some assemblers like ASL A and others like ASL when the operation is on the accumulator. Some like labels to have a trailing colon and some don't. Some might care about indentation. Kowalski uses () only to signify the addressing mode and uses [] to make up complex expressions. There are some which are even odder (Forthish or Lispy) but you're unlikely to meet them. BBC Basic's assembler allows multiple instructions on one line, and allows mingling of Basic and assembly. It also uses & for hex numbers where everyone else uses $.

So, these are little differences in detail, mostly. They do mean that you might not be able to copy and paste code, but you will usually easily be able to edit it into shape.


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 12:19 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
By and large, the actual 6502 instructions are written consistently. Some assemblers recognise more "alternative mnemonics" than others, eg BGE (Branch if Greater or Equal) becomes BCS (Branch if Carry Set). An exception is that most assemblers use $ as the prefix for hexadecimal constants, but BBC BASIC uses &.

The major differences lie in the assembler directives that go around the code, telling it where to put your code and defining labels among other things. BBC BASIC is perhaps the most extreme example, as you literally embed your assembly code in a BASIC program that acts as a macro processor for you. Other assemblers differ wildly in their support for directives and macros. Just about all you can count on is .ORG to locate your code and a : suffix to define a label, but even these don't work in BBC BASIC!


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 12:25 pm 
Offline

Joined: Mon May 21, 2018 8:39 am
Posts: 41
Phew! :shock:

I was scared for a moment. Now I understand. Okay, I think an afternoon reading of the manual of the x assembler will be okay....


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 12:29 pm 
Offline

Joined: Mon May 21, 2018 8:39 am
Posts: 41
I know it's too early for me to worry about macros but since you mentioned here, I would like to ask:

What IS a macro?

I bet it has to do with the assembler and not the actual 6502 assembly instructions/code

Can you give me an example?


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 12:32 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
The ZIP I attached to this post (http://forum.6502.org/viewtopic.php?f=1&t=5176) contains the source for a simple example 6502/65C02 program, the JAR containing my assembler/linker, an executable for my 65C816 emulator (that can be used to run and trace 6502/65C02 programs that don't use illegal or bit instructions) and some scripts to build and run them.

The source for the emulator is on GitHub (https://github.com/andrew-jacobs/emu816) and can be compiled on Windows or Linux. The assembler/linker needs a Java runtime. The Dev65 link in my signature goes to some documentation.

_________________
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  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 12:36 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
There's plenty of info and examples of macros in Garth's primer:
http://wilsonminesco.com/StructureMacros/


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 12:46 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
Kris1978 wrote:
I know it's too early for me to worry about macros but since you mentioned here, I would like to ask:

What IS a macro?

I bet it has to do with the assembler and not the actual 6502 assembly instructions/code

Can you give me an example?

You're just about right in your assumption. A macro is basically a form of shorthand for dealing with the repetitive structures that frequently show up in assembly code. There's at least one 6502 assembler out there which provides macros to implement common forms of loops, so your code is more readable because it looks a bit more like a high-level language. Generally a macro is replaced during assembly with a sequence of machine instructions, with parameters substituted.


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 6:15 pm 
Offline

Joined: Thu Jan 21, 2016 7:33 pm
Posts: 282
Location: Placerville, CA
In simple form, a macro is generally just a way of telling the assembler "replace this with that any time you see it," just like the assembler already does with labels or constants. (In fact, some assemblers, as well as some high-level languages like the C pre-processor, use the same syntax for both macros and constants.) So if you find yourself typing, say, a 16-bit addition sequence a lot:
Code:
lda value_a
clc
adc value_b
sta result
lda value_a + 1
adc value_b + 1
sta result + 1

...you can tell the assembler to define, say, ADD_WORD as an identifier that will expand to that code sequence. Frequently you can even set it up to accept parameters like a function in a high-level language, so that you can invoke it like ADD_WORD(value_a, value_b, result) and have the assembler make the necessary substitutions.


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Tue Jul 03, 2018 8:30 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
Kris1978 wrote:
Phew! :shock:

I was scared for a moment. Now I understand. Okay, I think an afternoon reading of the manual of the x assembler will be okay....

Yes, it's just some syntax details for the assembler, not any differences in the language itself. It would be nice if all assemblers were completely compatible; but differences may arise from various assembler writers' efforts to help the user make his code clear or to be able to adapt to various users' preferences, versus possible challenges like making the assembler fit in the very limited memory space of a smaller system. (To clear up some possible confusion in that statement: The assembler is the tool that converts assembly-language source code to the machine language that the processor can understand. The language itself is "assembly language," not "assembler." You'll see a lot of word misuse though.)

scotws wrote:
A big project forces you to learn how to structure the code at a whole different level.

+1. The beginner tends to not want to be bothered with things he regards as superfluous and making the source code "pretty." But as you gain experience and your projects get bigger and bigger, you'll find that it's easy to lose control of them and reach a point where you feel totally lost in your effort to find and fix a bug, make a change, etc., and you'll feel like the only solution is to start over! To minimize that growing pain, try to get into good habits early on. Admittedly, you won't initially know what these good habits even are; but do keep an open mind about the next strategies to learn.

Macros were mentioned earlier. I wouldn't spring them on the complete newbie, but I would encourage jumping in soon after the basics of assembly-language programming have become familiar. Ed linked above to my article on macros. It starts out with what a macro is, but the thrust of the article is to use them for the less-obvious things you can do with them, particularly program-flow-control structures.

A video I saw of a lecture on programming had a couple of great quotes:
  • Programs must not be regarded as code for computers, but as literature for humans.
  • Reducing size and complexity is the triumph.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Wed Jul 04, 2018 5:26 am 
Offline

Joined: Mon May 21, 2018 8:39 am
Posts: 41
Thank you all your valuable answers. Each one helped me in one or another way. 6502.org and wilsonminesco.com sites are indeed great sources of information. All I need is free time to study. Unfortunately I have a full time job (I'm a policeman) which means my spare time is very limited. For the time being I will stick with a free cross-platform assembler. The Kowalski assembler is my choice. I will read the help section in order to learn the syntax. Of course I will keep reading Rodnay Zak's and Randal Hyde's books. As for a target machine I think the Enhanced Apple IIe is the ultimate version of the 8-bit architecture. It keeps the simplicity of the NMOS 6502 without adding complexity and eliminates all harware bugs. The latter reason is why I prefer it over a BBC Micro (which undoubtedly is a stronger machine when comparing to an Apple ][) Later on I will move to an emulator for the Enhanced Apple IIe using Lisa assembler or Merlin assembler and finally I will try to purchase on eBay, a real Enhanced Apple IIe computer and....Godspeed! :)

P.s.Hope the above scenario won't last for ages till it will come true


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Wed Jul 04, 2018 5:47 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
Kris1978 wrote:
(I'm a policeman)

Thankyou for your service!

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Wed Jul 04, 2018 5:55 am 
Offline

Joined: Mon May 21, 2018 8:39 am
Posts: 41
You're welcome Garth although -unfortunately- I don't like my job. I do it just for the money (as millions of people do I guess)


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Wed Jul 04, 2018 6:31 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8545
Location: Southern California
Just stay true to your oath to uphold and defend the Constitution. Is your department the problem? The city near us has an outstanding police department, but we're slightly outside the city limits and we get the sub-standard "services" of the local sheriff's station. The deputies themselves say the problem is the Sheriff himself, the one running the department. Hopefully we'll have a new one soon who will turn things much for the better.

I've been asked to do another consulting task on the side, by a company that makes propulsion units for satellites. I like the engineering part, and it pays extremely well; but the down side is that everything has to have a load of red-tape certification processes which I hate. (As you can imagine, it's very expensive to launch a satellite, and once it's up there, if there's a failure, you can't exactly FedEx it back for repairs!) But I'm pushing through it because my wife lost her job. Otherwise I might tell them to go find someone else. I just want to finish the project and collect my ten grand or so.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Assembly programming
PostPosted: Wed Jul 04, 2018 6:52 am 
Offline

Joined: Mon May 21, 2018 8:39 am
Posts: 41
First of all, I'm a greek policeman. Just to make things clear. Second, I will disappoint you once again but it's the nature of the work that doesn't suit me. In addition, it's an absolutely non creative job at all. I admire people freelancers who go chase their future, creating useful stuff. Now a logical question must have be drawn in your head. Why I chose to enter the police academy in the first place (precisely 21 years ago)? First and foremost, I came from a poor family who couldn't support me if I attended a university. Secondly, there was no chance to attend a university since my grades were very low. I admit it, I'm lazy. Furthermore, in the beginning been a policeman seemed a very appealing job and been a young guy, I didn't have the smartness(?) to sit down seriously and think what I really like to do in my life and how to find a work around in order to succeed it. Anyway. End of drama. I think we are off-topic!!! :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 10 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: