Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Learning Assembly Language

Status
Not open for further replies.

PurduePete

Newbie level 5
Joined
Jan 19, 2012
Messages
8
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,418
Hey everyone,

I had a question about learning assembly language. I am new to PIC programming, which is what I have decided to start with rather than another type. A few sources and articles have suggested learning assembly programming rather than C. This far I agree but wanted to know what everyone else thought about that. Assembly takes less space and doesn't need another program such as MickroC. I don't want to pay for that so its a plus for me. Also I am not an amazing programmer.

My next question is how to learn CURRENT assembly programming. The text book I downloaded from my universities library is PIC Microcontroller: an introduction third edition by Martin bates. It uses a 16F84A and a 16F88 later on. The first is out of date and so far the book has good explanations but I'm worried it's too dated. I own a 12F683 and a 16F688 again the first is a touch dated. I'd like to learn how to write programs for both. Has anyone got free tutorials, PDFs, or videos for beginner assembly language? I would like video explanations so that someone explains it to me. But reading is obviously fine.

Thanks for everyone's time, hope you guys have some ideas. I have searched but most people seem to use C rather than assembly so not a lot on it, least I didn't see much.
 

Hi,

Assembler v C is an old argument that will always persist, it sounds as if you are already favouring Assembler so suggest you persue that, it does teach you a lot about the detailed functions of the chip.

As for CURRENT assembler - not really - its all much the sameness, just that some of the later chip introduce more hardware features.
Most 16F program will run on your 688 with minimal modification.

C is the long term way things are going because hi end tasks like USB, CAN rely on C modules supplied by Microchip.

A simple google will provide many online tutorials here are a couple of the popular ones.

Nigel's PIC Tutorial Page

**broken link removed**

Plenty of help here if you get stuck..

Enjoy
 
wp100 beat me to posting the Gooligum Tutorial Link, I can't recommend those tutorials enough.

They cover both the Baseline and Midrange PICs, using both Assembly and HiTech C languages and are the most professionally done tutorials available online at no cost.

When coding for the PIC12F and PIC16F series, pay particularly close attention to the use of Assembly Directives "banksel" and "pagesel" which is often an issue with novice coders.

If and when you are ready to branch out to C programming the HiTech C Compiler for this series of PICs is available free for use in "Lite" mode:

**broken link removed**

The second half of the Gooligum Tutorials does an excellent job of cover the HiTech C Compiler.

BigDog
 

Thanks guys.

Its not that I won't learn C, I just feel like for the little things that I will be doing for now it makes more sense to use Assembly. C is very useful for a lot of program so I'm going to pick it up eventually. I honestly didn't think about things like the USB interface requiring C code to work properly.

I like the link to Nigel's stuff, that so far looks pretty good. I'm going to print out the first tutorial and read through it and try and use the text book I've got to explain everything if he doesn't. Haven't had much time to look yet though. Hadn't seen either of those yet so thanks for the post. I appreciate the posts.

I'm struggling right now with how to define ports on my 12F as they are not defined as ports but as GPIO (General Purpose Input Output). Also having some trouble with defining just one bit and making it output to turn on an LED alone. I think that these two tutorials will help me out. The textbook hasn't covered any of the general config yet that is at the top of the code on Nigel or the Comparators or the ANSEL portion yet and I am on chapter 5. These are the things confusing me, so hopefully these tutorials will really help with that.

Again, thanks guys. I appreciate it. If you have any other suggestions for someone to learn this stuff, let me know.

John
 

I would recommend you examine the first lesson of the Gooligum Midrange PIC Assembly Language Tutorials:



**broken link removed**

The lessons of the tutorials make use of a PIC12F629 and later the PIC16F684.

Therefore the lessons deal directly with the differences in nomenclature between the PIC12F and PIC16F series, like PORT definitions, GPIO vs. PORTA.

BigDog
 

Hi,

The author of the WinPicProg Tutorial is still contactable in the Electro Tech forum, most of his stuff is good if you like his style.

Have used some of his code in the past , the only thing I would take issue with is his ADC tutorial, for a beginner a simple 10k pot directly connected to the Pics ADC pins would suffice, but he overly complicates it by using an op amp buffer and reference voltage diode, good stuff but not needed at such an early stage of learning.


I don't do Pic C, but have tried a bit of C++ using a little Arduino UNO, with its massive free libraries you virutally 'borrow' the code and have a working project in minutes.
Some years ago I spent weeks writing my own GLCD 128x64 assembler code, yet on the UNO I had it running in literally 10 minutes.

So many choices for you... are you doing it purely as a hobby or looking to make future use of it in college or professionally ?
 

A couple of very good tutorials have been mentioned already. I am relatively new at Assembly too. When I just began, however, I found some of the tutorials a bit overwhelming. For example, one introduced the symbol "$-1" without explaining it. That was a tough search on my PC. Googligum does similar things. Least I be misunderstood, at this point in my education, Googligum is still my favorite. But why, in its discussion of tables (See: Midrange Assembler, Lesson 12, page 6), does the author suddenly introduce "retlw 0" to a table that never before had one? "retlw" should be self explanatory in a table.

When I just began flashing led's, I found the following very helpful and could recommend either one:

**broken link removed**
Elmer 160 -  Course Lessons

My advice is to pick just one tutorial ( I happen to like Elmer) until you get that first LED flashing. Then fill out your knowledge with the others.

John
 

A couple of very good tutorials have been mentioned already. I am relatively new at Assembly too. When I just began, however, I found some of the tutorials a bit overwhelming. For example, one introduced the symbol "$-1" without explaining it. That was a tough search on my PC. Googligum does similar things. Least I be misunderstood, at this point in my education, Googligum is still my favorite. But why, in its discussion of tables (See: Midrange Assembler, Lesson 12, page 6), does the author suddenly introduce "retlw 0" to a table that never before had one? "retlw" should be self explanatory in a table.

When I just began flashing led's, I found the following very helpful and could recommend either one:

**broken link removed**
Elmer 160 -* Course Lessons

My advice is to pick just one tutorial ( I happen to like Elmer) until you get that first LED flashing. Then fill out your knowledge with the others.

John


Hi,

Good comment, though it highlights how difficult writing a tutorial can be.

That why using this and similar forums can be so helpful in filling in the gaps like you mention.

Don't forget that there is also a good active Microchip forum
Microchip
 

I believe it also should be pointed out, an often helpful but overlooked resource is the following documentation:

MPASM/MPLINK User's Guide

Microchip's MPASM/MPLINK documentation tends to be quite in depth with code examples.

BigDog
 

@wp100
When one is just starting, too many slightly different approaches can be worse than one imperfect approach. I actually tried to consolidate the tutorials of Nigel Goodwin, Tracey, and Elmer into one. Impossible. It was like an alien visitor trying to take Russian, Chinese, and English to make a single language for communication with humans. I settled on one tutorial and got my first few projects done.

Now that I am a just little past that, I am getting to know what real Assembly programmers do. I don't understand much of it, but I realize there is a whole new world of Assembler Directives and macros. You mention the Microchip forums. They are good, but a rank beginner may be confused by them. I prefer PicList (@piclist.com). It is amazing what you can do with a few simple instructions, like bsf, bcf, movlw, movf, movwf, andwf, btsfc, btfss, comf, and a delay (etc.).

The original poster commented about the 12F683 being dated. While that may technically be true compared with chips such as the 12F1840, I would not recommend even starting with the 12F6XX chips. The 12F5xx chips are great for starting, and one does not have to worry about all of the various potential functions pins may have.

As an example, I just moved from the 12F509 to the 12F683. Today, I was simulating a program of more than 256 steps (about 6 pages printed out) with look-up tables and was having problems with a stimulus that would fire only inconsistently. (The program included some 32-byte math routines, so I wanted to check them out thoroughly.) It would work on GP4, but not GP0. I had turned comparators and so forth off and spent a lot of time worrying about the inconsistency. Viewing "Output" eventually came to the rescue with a comment that a pin controlled by an ADC cannot be stimulated. Why didn't that appear every time I fired the stimulus???? Anyway, I had forgotten/not realized that I also had to turn off ANSEL. As I recall, the 12F1840 has in excess of 100 SFR's. I can't imagine beginning with that chip.

The excitement of getting your first, self-written program to run may be forgotten by those who have been doing it a few years, but for me the memory is still fresh. My advice is still, pick one teacher/tutorial and start simple. While not perfect, it is still better than giving up in frustration or being continually dependent on cutting-and-pasting code written by others.

Regards, John

BTW, I started with virtually zero experience in writing any code. My comments might not apply for a younger person who has been exposed through osmosis.
 

So many choices for you... are you doing it purely as a hobby or looking to make future use of it in college or professionally ?

I'm doing this to learn a bit of the logic behind programming. I could pick up regular C programming pretty quick as I've done it in a few classes but I'd rather be able to do something with my programming and build things. Yes I know about using C to program but I've decided assembly first and then C and then move on to C++. As many different types of programming will be great as an engineer. My girlfriend's Dad, who is an electrical engineer, suggested becoming proficient at programming as his team always needs someone to do that stuff. Also always looking for little projects that I've never done before.... or large projects :D I don't do much with electronics honestly, usually work on motorcycle projects for fun (in fact getting a 73' CB500 this weekend to work on). Just always wanted to learn more about electronics so here I am giving it a go.

As jpanhalt pointed out it seems that a lot of the tutorials and even text books introduce things without explaining them in the least. For instance in the winpicprog tutorial, which I really like so far, the author introduces the first three lines as required by the chip and then moves on. I want to use my 688 chip and not the 628 chip so I'd like to know how to set the config and can't really figure that out from any tutorials thus far. I also would like a better explanation of the comparators being turned off by taking the work register which has 7 in it and putting it into the CMCON register. Here is the line if someone cares to explain that little bit to me:


Code ASM - [expand]
1
2
3
4
5
6
7
8
9
10
;Tutorial 1.1 - Nigel Goodwin 2002
        LIST    p=16F628                        ;tell assembler what chip we are using
        include "P16F628.inc"           ;include the defaults for the chip
        __config 0x3D18                 ;sets the configuration settings 
                                                ;(oscillator type etc.)
 
        org     0x0000                  ;org sets the origin, 0x0000 for the 16F628,
                                                ;this is where the program starts running       
        movlw   0x07
        movwf   CMCON           ;turn comparators off (make it like a 16F84)



I've been looking through the 628 datasheets for these answers but so far haven't come up with what I need. These tutorials are still be code than my text book and have far better explanations. I can't even imagine trying to cover every single base for everyone, so on the whole I think this author has done a great job. I'm just having trouble picking it up is all. Once I get the configurations of the chip down such as turning off comparators, defining the output bits, and learn about different banks I'll be good to write some programs on my own I think. This community has already been a great help.
 

A much more intuitive method of configuring the Configuration Register is by the use of the Configuration Register Bit Masks contained in the p16f688.inc file.

Reference: p16f688.inc
Code:
;==========================================================================
;
;       Configuration Bits
;
;   NAME            Address
;   CONFIG            2007h
;
;==========================================================================

; The following is an assignment of address values for all of the
; configuration registers for the purpose of table reads
_CONFIG          EQU  H'2007'

;----- CONFIG Options --------------------------------------------------
_LP_OSC              EQU  H'3FF8'    ; LP oscillator: Low-power crystal on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
_XT_OSC              EQU  H'3FF9'    ; XT oscillator: Crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKINT
_HS_OSC              EQU  H'3FFA'    ; HS oscillator: High-speed crystal/resonator on RA4/OSC2/CLKOUT and RA5/OSC1/CLKIN
_EC_OSC              EQU  H'3FFB'    ; EC: I/O function on RA4/OSC2/CLKOUT pin, CLKIN on RA5/OSC1/CLKIN
_INTOSCIO            EQU  H'3FFC'    ; INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_INTRC_OSC_NOCLKOUT  EQU  H'3FFC'    ; INTOSCIO oscillator: I/O function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_INTOSC              EQU  H'3FFD'    ; INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_INTRC_OSC_CLKOUT    EQU  H'3FFD'    ; INTOSC oscillator: CLKOUT function on RA4/OSC2/CLKOUT pin, I/O function on RA5/OSC1/CLKIN
_EXTRCIO             EQU  H'3FFE'    ; EXTRCIO oscillator: External RC on RA5/OSC1/CLKIN, I/O function on RA4/OSC2/CLKOUT pin
_EXTRC_OSC_NOCLKOUT  EQU  H'3FFE'    ; EXTRCIO oscillator: External RC on RA5/OSC1/CLKIN, I/O function on RA4/OSC2/CLKOUT pin
_EXTRC               EQU  H'3FFF'    ; EXTRC oscillator: External RC on RA5/OSC1/CLKIN, CLKOUT function on RA4/OSC2/CLKOUT pin
_EXTRC_OSC_CLKOUT    EQU  H'3FFF'    ; EXTRC oscillator: External RC on RA5/OSC1/CLKIN, CLKOUT function on RA4/OSC2/CLKOUT pin

_WDT_OFF             EQU  H'3FF7'    ; WDT disabled
_WDT_ON              EQU  H'3FFF'    ; WDT enabled

_PWRTE_ON            EQU  H'3FEF'    ; PWRT enabled
_PWRTE_OFF           EQU  H'3FFF'    ; PWRT disabled

_MCLRE_OFF           EQU  H'3FDF'    ; MCLR pin function is digital input, MCLR internally tied to VDD
_MCLRE_ON            EQU  H'3FFF'    ; MCLR pin function is MCLR

_CP_ON               EQU  H'3FBF'    ; Program memory code protection is enabled
_CP_OFF              EQU  H'3FFF'    ; Program memory code protection is disabled

_CPD_ON              EQU  H'3F7F'    ; Data memory code protection is enabled
_CPD_OFF             EQU  H'3FFF'    ; Data memory code protection is disabled

_BOD_OFF             EQU  H'3CFF'    ; BOR disabled
_BOR_OFF             EQU  H'3CFF'    ; BOR disabled
_BOD_SBODEN          EQU  H'3DFF'    ; BOR controlled by SBOREN bit of the PCON register
_BOR_SBODEN          EQU  H'3DFF'    ; BOR controlled by SBOREN bit of the PCON register
_BOD_NSLEEP          EQU  H'3EFF'    ; BOR enabled during operation and disabled in Sleep
_BOR_NSLEEP          EQU  H'3EFF'    ; BOR enabled during operation and disabled in Sleep
_BOD_ON              EQU  H'3FFF'    ; BOR enabled
_BOR_ON              EQU  H'3FFF'    ; BOR enabled

_IESO_OFF            EQU  H'3BFF'    ; Internal External Switchover mode is disabled
_IESO_ON             EQU  H'3FFF'    ; Internal External Switchover mode is enabled

_FCMEN_OFF           EQU  H'37FF'    ; Fail-Safe Clock Monitor is disabled
_FCMEN_ON            EQU  H'3FFF'    ; Fail-Safe Clock Monitor is enabled


Example:
Code:
;   Set configuration bits using definitions from the include file, p16f688.inc
	__config	 _HS_OSC & _WDT_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOR_OFF & _FCMEN_OFF

You can determine all the Configuration Register settings at a glance, which makes configuring and troubleshooting any Configuration Register issues much easier and far less error prone.

By adding the device specific inc file, p16f688.inc in your case, to the project window, you can easily reference it while coding.

When applying the Configuration Register settings in code, you should ensure the "Configuration Bits set in Code" box is checked in the "Configure" =>"Configuration Bits" window of MPLAB.

BigDog
 

I want to use my 688 chip and not the 628 chip so I'd like to know how to set the config and can't really figure that out from any tutorials thus far.

Here are two crutches I use:
1) Find other examples of code for the same chip and see what was used; and
2) Go to the Configure > Configuration Bits... dialog in MPLab, unclick the set in code box, see what your options are, make your selection and let the program do the math to get you the hex for configuration. Generally, the descriptions of the choices in the drop-down menus are self-explanatory. When that is not the case, the datasheet explains it in more detail. I then re-click the box and go back to the configuration line to enter my choices. I comment out the resulting hex but keep it visible for a reminder.

I also would like a better explanation of the comparators being turned off by taking the work register which has 7 in it and putting it into the CMCON register.

The decimal '7' is just setting the register's bits to b'00000111'. The three LSB's turn off the comparators. That setting is explained in the datasheet.

Remember, there are different approaches to reach the same result. In this recent thread elsewhere, Assembler Directives and Operators Confusion , I raised a similar point about which method was most easily understood. That led to quite a discussion by individuals who do Assembly coding for a living.

John
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top