Register to reply

Assembly language programming?

by mathrocks
Tags: assembly, language, programming
Share this thread:
mathrocks
#1
Nov9-04, 11:07 PM
P: 106
I'm working on a project that I believe should be pretty simple to do if I actually knew assembly language.
For my program I'm suppose to start at data memory location 0x30 and perform the increment, decrement, complement, and clear operations. The operations are all performed on location 0x21...i.e. add 1 to location 0x21 (increment).

So given that, is this program really that simple? Or is there some tricky stuff involved?

Does anyone know of a good website to learn assembly language? And if you guys have any hints or suggestions on how I should get started with this program please help me out! I'm really just having trouble with the whole memory concepts, I'm not used to messing around with that.

Thanks!
Phys.Org News Partner Science news on Phys.org
Sapphire talk enlivens guesswork over iPhone 6
Geneticists offer clues to better rice, tomato crops
UConn makes 3-D copies of antique instrument parts
gnome
#2
Nov9-04, 11:52 PM
P: 1,047
The commands to perform those memory operations are very simple, but you need to know the overall structure of an assembly language program before you can write one. Here are a couple of links:

http://www.osdata.com/topic/language/asm.htm
http://atrevida.comprenica.com/
chroot
#3
Nov10-04, 02:58 AM
Emeritus
Sci Advisor
PF Gold
chroot's Avatar
P: 10,429
The best way to learn assembly is to use inlining. If you're using the Microsoft Visual C++ compiler, you can embed assembly into your C++ code like this:

PHP Code:
int multiplyByTwo(int a)
{
   
__asm
   
{
       
mov eaxa
       mul eax
2
   
}

The return variable is left in the eax register. You can refer to C++ variables (like a) directly in the assembly instructions.

(You can inline asm with other compilers like gcc, but the syntax is much more convoluted.)

If you need a reference to the Intel x86 instruction set, the best place to go is Intel itself: ftp://download.intel.com/design/Pentium4/manuals/

Look into the mov, inc, dec, clr and other instructions in those manuals.

If you have any more specific questions, let us know!

- Warren

poolwin2001
#4
Nov10-04, 08:17 AM
P: 173
Assembly language programming?

(You can inline asm with other compilers like gcc, but the syntax is much more convoluted.)
in TC (if anybody is using that now)
you have
//
asm{
mov ax,dx
};
etc
mathrocks
#5
Nov10-04, 11:52 AM
P: 106
Quote Quote by gnome
The commands to perform those memory operations are very simple, but you need to know the overall structure of an assembly language program before you can write one. Here are a couple of links:

http://www.osdata.com/topic/language/asm.htm
http://atrevida.comprenica.com/
This is my code as of now. I'm pretty sure it's totally wrong, but logically it seems right to me, increment 0x21, decrement 0x21, complement 0x21, and then clear it? I think it's just the memory stuff that's giving me a hardtime(i hope).



list P=16F84
include P16F84.INC

; Define the direction bit types
f equ 1
w equ 0

; Define the data storage locations
org 0x20
cnt res 1;the number of instructions to execute (1<=n<=8)
acc res 1 ;the accumulator


org 0x30
prg res 8 ;location of the program

; start defining the program

; no interrupts, so start at 0x0

org 0x0
goto INC

INC
org 0x30
incf 0x21, 0
goto DEC


DEC
org 0x31
decf 0x21, 0
goto COM


COM
org 0x32
comf 0x21, 0
goto CLR


CLR
org 0x33
bcf 0x21, 7
goto endless

endless nop
goto endless
end
mathrocks
#6
Nov10-04, 04:54 PM
P: 106
Ok, I'm understanding this a little better now, my other code was totally wrong.
I'm suppose to perform the operation according to the opcode. If its 0x00 I increment, 0x01-decrement, 0x02-complement, 0x03-clear. My only question now is how do I look at the bits and see if it's a 0, 1, 2, or 3? I'm sure there's a certain operation that looks at the bits but I'm not familiar with it. This is my code thus far, I hope I'm at least on the right track.



list P=16F84
include P16F84.INC

; Define the direction bit types
f equ 1
w equ 0

; Define the data storage locations
org 0x20
cnt res 1 ;the number of instructions to execute (1<=n<=8)
acc res 1 ;the accumulator


org 0x30
prg res 8 ;location of the program

; start defining the program

; no interrupts, so start at 0x0

org 0x0
movlw 0x21
goto main

Main
*Check sign for 0x00*
goto INC

*Check sign for 0x01*
goto DEC

*Check sign for 0x02*
goto COM

*Check sign for 0x03*
goto CLR


INC
org 0x30
incf 0x21, w
goto main
DEC
org 0x31
decf 0x21, w
goto main

COM
org 0x32
comf 0x21, w
goto main

CLR
org 0x33
bcf 0x21, 7
goto endless

endless nop
goto endless
end
mathrocks
#7
Nov10-04, 07:21 PM
P: 106
Does anyone have any suggestions?
gnome
#8
Nov10-04, 08:51 PM
P: 1,047
What is that?

It doesn't look anything like the 80x86 assembly language I learned a couple of years ago.
mathrocks
#9
Nov10-04, 09:57 PM
P: 106
Quote Quote by gnome
What is that?

It doesn't look anything like the 80x86 assembly language I learned a couple of years ago.
I'm using assembly language to program a PIC...PIC16F84 to be specific. I don't know, I guess it can differ?
gnome
#10
Nov10-04, 10:26 PM
P: 1,047
I guess so. It's totally different. If you're curious, I can post an example of a simple TASM (that's Borland Turbo Assembler) program for 8086. (If not, I won't clutter up your thread.)
mathrocks
#11
Nov10-04, 10:36 PM
P: 106
Quote Quote by gnome
I guess so. It's totally different. If you're curious, I can post an example of a simple TASM (that's Borland Turbo Assembler) program for 8086. (If not, I won't clutter up your thread.)
Yeah, that would be fine. I'm interested in seeing how different it is.
gnome
#12
Nov10-04, 10:42 PM
P: 1,047
Here's a pretty simple example. The stuff following the semi-colons on each line are comments, so it should be fairly easy to follow what it's doing. As you can see, much of the action involves moving data into and out of cpu registers.

% TITLE 'Arithmetic/DOS functions'



	IDEAL

	MODEL small

	STACK 100h



; equates

CR	equ	13

LF	equ	10

delimiter equ	'$'



	DATASEG

n1	dw	200

n2	dw	?

n3	dw	?

temp	dw	?

x	db	10

y	db	20

z	db	?

c	db	?

msg1	db	CR,LF," input a character",CR,LF,CR,LF,DELIMITER

msg2	db	"you pressed the character :  ",DELIMITER

msg3	db	"now the character is :  ",DELIMITER



	CODESEG

START:

	mov	ax,@data

	mov	ds,ax

	mov	ax,[n1]	;ax=n1

	sub	ax,25	;ax=ax-25 (=n1-25)

	mov	[n2],ax	;now n2=n1-25

	mov	ax,1	;ax=1

	sub	[n1],ax	;n1=n1-ax (=n1-1)

	mov	ax,[n1]	;ax=n1

	add	ax,[n2]	;ax=ax+n2 (=n1+n2)

	mov	[n3],ax	;n3=ax (=n1+n2)

	sub	[n3],10	;n3=n3-10 (=n1+n2-10)



	mov	ax,[n1]	;ax=n1

	mov	[temp],ax ;temp=ax (=n1)

	mov	bx,[n2]	;bx=n2

	mov	[n1],bx	;n1=bx (=n2)

	mov	[n2],ax	;n2=ax (=temp)

	

	mov	ah,[x]	;ah=x

	mov	al,[y]	;al=y

	sub	al,ah	;al=al-ah (=y-x)

	mov	ah,00	;ah=0

	mov	[n3],ax	;n3=ax (=(int)y-x)

	sub	[n3],1	;n3=(int)y-x-1)



	mov	ah,9	;storing DOS string output function# in ah

	mov	dx,OFFSET msg1	;stores label of string to print in dx

	int	21h	;DOS call

	mov	ah,1	;storing DOS key input function# in ah

	int	21h	;DOS call

	mov	[c],al	;retrieve char input from al register

	mov	ah,9	;storing DOS string output function# in ah

	mov	dx,OFFSET msg2	;stores label of string to print in dx

	int	21h	;DOS call

	mov	ah,2	;DOS char output function#

	mov	dl,[c]	;storing char to output in dl

	int	21h	;DOS call

	mov	dl,CR	;storing ASCII CR code in dl (function# 2 is already in ah)

	int	21h	;DOS call

	mov	dl,LF	;storing ASCII LF code in dl (function# 2 is already in ah)

	int	21h	;DOS call



	mov	bx,OFFSET c	;stores address of c in bx

	mov	al,[x]	;copies x to al (al=x)

	add	[bx],al	;add al to c (c=c+al) ([bx] is pointer to c)

	sub	[byte ptr bx],7	;subt 7 from c (c=c-7) ([bx] is pointer to c)



	mov	ah,9	;DOS string output function#

	mov	dx,OFFSET msg3	;stores label of string to print in dx

	int	21h	;DOS call

	mov	ah,2	;DOS char output function#

	mov	dl,[c]	;stores char to output (c) in dl

	int	21h	;DOS call

	mov	ah,4ch	;stores DOS terminate program function# in ah

	int	21h	;DOS call

	END	START
NoTime
#13
Nov10-04, 11:56 PM
Sci Advisor
HW Helper
P: 1,571
Quote Quote by mathrocks
how do I look at the bits and see if it's a 0, 1, 2, or 3?Does anyone have any suggestions?
I don't know that particular uP, but you can always use an AND instruction to test bits.
like:
AND data1,11111101b
jump_not_zero The_number_is_not_two
AND data1,00000010b
jump_not_zero Only_bit_2_on /* the value is two */
jump_zero The_value_is_zero

Notes:
Some uP will require a separate move to work register for data1.
This example requires two such moves since the first test is destructive.

Other uP put the result in a work register.
In this case the test is not destructive.

Almost all uP will set the zero flag on an AND without a seperate compare instruction.

You need to learn the available instructions in order to be effcient.
Some uP have specific instructions to test bits.
chroot
#14
Nov11-04, 02:19 AM
Emeritus
Sci Advisor
PF Gold
chroot's Avatar
P: 10,429
...and most people (including me) will assume that you're talking about x86 assembly unless you specify otherwise.

- Warren
jimvoit
#15
Jul2-08, 12:09 PM
P: 72
Take Chroot’s recommendation and go to Intel and read their manual. Whether it is worth your while learning an assembly language depends on your interests, your job, and the people you will be working with. If you are working with engineers building embedded systems, or designing embedded system yourself, I’d say it would be a very good idea to be familiar with the assembly language of the microcontrollers that you or they are working with.
jimvoit
#16
Jul2-08, 07:37 PM
P: 72
Sorry...The above response was to another thread that I pasted in the wrong place..
TudorOSasker
#17
May22-11, 03:35 AM
P: 2
i dont really know, one thing thats amazing is that i know assembly and im only 11. Here are sites i visited to help, Art of assembly, emu8086, fasm, osdev, intel. But who cares what sites. did you know i learned some imaginary assembly then i jmped when i saw real assembly(not real-mode, x86 assembly)
TudorOSasker
#18
May22-11, 03:36 AM
P: 2
I need a list of all IO port numbers


Register to reply

Related Discussions
Assembly Language Electrical Engineering 10
Assembly Language Engineering, Comp Sci, & Technology Homework 0
Assembly language Electrical Engineering 5
Need help programing in assembly language Programming & Computer Science 1
Turbo Assembly Language Computing & Technology 2