There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
need assembly language code


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
jolly1808's Avatar
Member with 37 posts.
 
Join Date: Mar 2006
16-Oct-2006, 09:13 AM #1
need assembly language code
hi there, i have this question, yes it is work i have to do, so dont bother wasting your/mine time saying do it by your self, thanks.

i am told the high-level language:
For I <-- 1 To 10 Do
A <--- A + 1;
i want to write this int he assembly language equivalent of this.

would be greatly appreciated if you could help,
thanks alot
lotuseclat79's Avatar
Distinguished Member with 10,043 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
16-Oct-2006, 09:37 AM #2
Quote:
Originally Posted by jolly1808
hi there, i have this question, yes it is work i have to do, so dont bother wasting your/mine time saying do it by your self, thanks.

i am told the high-level language:
For I <-- 1 To 10 Do
A <--- A + 1;
i want to write this int he assembly language equivalent of this.

would be greatly appreciated if you could help,
thanks alot
Hi jolly1808,

If I is your index, then where is I used in A <--- A + 1;? If you intend A to be an array then you need to index A with I to initialize the array if that is your intention.
In assembler language, registers or memory can be used to implement an array.

A simple way to understand the assembler code, is to write it in C, and after the C program is verified to work, then recompile and toggle the compiler switch that emits assembler language code to see how it is done by the C compiler, or choose another language that emits assembler, then adapt it for your use.

-- Tom
__________________
The independence created by philosophical insight is - in my opinion - the mark of distinction between a mere artisan or specialist and a real seeker after truth. - Einstein wrote in 1944.

Some say knowledge is power, I say knowledge without action is powerless. - lotuseclat79

Don't confuse action with movement. - Hemingway to Gardner

Imagination is more important than knowledge. - Einstein
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
16-Oct-2006, 09:53 AM #3
What processor for Intel 8088 it would be:

Code:
   mov   cx,10  ; cx is typically used as a counter register in intel

lable_1:
   ; based on your pseudo code
   inc   ax        ;  A<--A + 1

   inc   cx
   cmp   cx, 0
   jg   lable_1
jolly1808's Avatar
Member with 37 posts.
 
Join Date: Mar 2006
16-Oct-2006, 12:00 PM #4
thanks both of you for your reply, unfortinatly, i cant really understand what you are saying.
i have just started to learn how to write with assembly language (like yesterday), and according to my guide, i should be able to write the program

for i <-- 1 to 10
a <-- a + 1;

in assembly language.

so far, the coomands i have learnt is:
LD, ST, MOVE, ADC, SBC, INC, DEC, NOT, ADC, and i have read on to read about CLC, RTS and ASL.

if someone or dquigley himself and re-write what dquigley wrote using the commands i have learnt so i can follow what you are doing would be really great.

thanks for any help you can give me,,, 1 day i will understand this
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
16-Oct-2006, 12:14 PM #5
To help you I need to know what processor you are writing this code for. From the instructions you list, it appears like an ARM or AVL RISC processor.

Best,
Dan
jolly1808's Avatar
Member with 37 posts.
 
Join Date: Mar 2006
16-Oct-2006, 12:15 PM #6
Quote:
Originally Posted by dquigley
To help you I need to know what processor you are writing this code for. From the instructions you list, it appears like an ARM or AVL RISC processor.

Best,
Dan
thanks again for your help, but i must stress that i am not writting this for any processor, im am just simply learning about assembly language.
EDIT: i am told that these codes are used for a typical computer system.
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
16-Oct-2006, 12:26 PM #7
Every processor family has unique instructions sets and syntax. "Assembly Language" is not standardized like higher level languages like C or C++. When you write in "Assembly" you write to a specific processor/family. Like Intel 80xxx or TI2430 or Motorola 6502, etc. Assemblers take text representations of instructions and assemble them into machine readable code. They are typically designed and developed by the processor manufacturer and vary in features and capabilities.

Somewhere in the materials you are reading there should be something that tells you what processor those instructions are for.

Best,
Dan
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
16-Oct-2006, 12:32 PM #8
If this is a "generic" assembly language class, then I will need to know the description of the processor and each instruction. I don't see any in the list you provide that stands out as a branch/test or loop instruction. You will need one or more of those to code the FOR loop.

Best,
Dan
jolly1808's Avatar
Member with 37 posts.
 
Join Date: Mar 2006
16-Oct-2006, 12:52 PM #9
unfortinatly i can not tell you what proccessor it is for, all i am told is that these instructions are a set of a typical computer.

i really appericate your help, and lasting this long with me,,
so far, this is what i have come up with:

let i = B
----------------------------------------------------------------------------------------------------
LD B
LD A #0
IN B
CMP B #10 (label = label_1)
JMP label_stop
HALT (label = label_stop)

yeah so,, i really am stuck
this code above prob makes no sense, but thought i would write it to see if you can kinda get from that what i mean/ment to do,
again, thanks so much for trying to help.

EDIT
perhaps this would help tough, i am givin as an example:
Q: write assembly language of this:
A<-- 0;
Repeat
A<-- A + 1;
Until A = 99

A:
LD A, #0
ST A, LOCA
LD A, LOCA (label = REPEAT)
INC A
STA, LOCA
CMP A, #99
JPNZ REPEAT
HALT

EDIT2:
LD A, memref --> loads the info identified by memref into the register A
ST A, memref --> stores the contents of reg A into the location identified by memref
INC A --> adds 1 to the value in reg A
CMP A, memref --> compares the contents of reg A with the data identified by memref, and sets the Zero flag if they are equal
JP coderef --> jmps to the code location labelled coderef
JPZ coderef --> as for JP, but the jump only happens if the zero flag is set
JPNZ --> as for the JPZ, but the jump only happensif the zero flag is set
HALT --> stop

Last edited by jolly1808 : 16-Oct-2006 01:31 PM.
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
16-Oct-2006, 01:31 PM #10
From the looks of things, the basics haven't clicked with you yet. For a simple computer think of four basic things:

1) Processor Instructions - perform actions on registers and/or memory

2) Processor Registers - temporary holding places for values

3) Processor Flags - a special register (on some chip architectures) that holds status/state values

4) Memory - holds both code (instructions) and values (data)

A simple loop that does not use memory (just registers) is:

Code:
LD A, #0   ; load register A with the value 0
LD B, #10  ; load register B with the value 10

:LOOP1     ; a label - this tells the assembler to remember the 
           ; location (in memory) of the next instruction ("INC A" in this case)

INC A      ; increment register A by 1
DEC B      ; decrement register B by 1

; depending on the processor this next instruction may not be required
; because on some processors the zero flag is set when any register is
; decremented or incremented to the value zero

CMP B, #0  ; compare the value in register B with 0 (this sets or clears a flag 
           ; usually in a special flags register)
JPNZ LOOP1 ; if the zero flag is not set (off) jump to label LOOP1 (location of "INC A")
HALT
jolly1808's Avatar
Member with 37 posts.
 
Join Date: Mar 2006
16-Oct-2006, 02:05 PM #11
hey, thanks this really helps,

so, for my problem:
For I = 1 to 10 do (let I = B)
a = a + 1

a possible way to answer this is:

LD A, #0
LD B, x ; x is my input
:loop1
cmp B, #10
INC A
INC B
JPNZ loop1
HALT

this seems quite simple.... would this be correct ?

ACTAULLY, this would go on forever, i will change it to:
LD A, #x
LD B, 0 ; x is my input
:loop1
INC A
INC B
cmp A, #10
JPNZ loop1
HALT

Last edited by jolly1808 : 16-Oct-2006 02:19 PM.
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
16-Oct-2006, 02:40 PM #12
Code:
LD A, #x
LD B, 1 ; x is my input  B needs to start at 1 per your problem  FOR I = 1 to 10 (let I=B)
:loop1
INC A
INC B
cmp B, #10 ; need to compare B
JPNZ loop1 
HALT
jolly1808's Avatar
Member with 37 posts.
 
Join Date: Mar 2006
16-Oct-2006, 02:47 PM #13
Quote:
Originally Posted by dquigley
Code:
LD A, #x
LD B, 1 ; x is my input  B needs to start at 1 per your problem  FOR I = 1 to 10 (let I=B)
:loop1
INC A
INC B
cmp B, #10 ; need to compare B
JPNZ loop1 
HALT
i cant thank you enough for helping me here, not only did u answer my question, but now i completly understand how you did it.
last thing, is it only values in the accumlator that can be compared, or can any value inany registar be compared ?
dquigley's Avatar
Computer Specs
Senior Member with 112 posts.
 
Join Date: Apr 2006
Location: Woodinville, WA
Experience: Advanced
16-Oct-2006, 04:58 PM #14
You're welcome.

Most modern processors allow you to compare all registers and memory etc. For example in an Intel segmented model the following code will compare two 16 bit values, each in memory:

Code:
cmp ds:[si], es:[di]  ; [] brackets around a register instruct the processor
                      ; to reference a location in memory not the value of the register

This is a pretty good site about Assembly.
The Art of Assembly Language Programming

Good Luck,
Dan
lotuseclat79's Avatar
Distinguished Member with 10,043 posts.
 
Join Date: Sep 2003
Location: -71.45091, 42.27841
19-Oct-2006, 08:24 AM #15
Here is another good link about assembly language:
http://en.wikipedia.org/wiki/Assembly_language

-- Tom
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 03:27 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.