Actions

  Print Article
  BookMark Article

Categories    Category List

Arts & Humanities
  Books & Authors
  Dancing
  Genealogy
  History
  Performing Arts
  Philosophy
  Poetry
  Theater & Acting
  Visual Arts
Beauty & Style
  Fashion & Accessories
  Hair
  Makeup
  Skin & Body
Business & Finance
  Advertising & Marketing
  Careers & Employment
  Corporations
  Credit
  Insurance
  Investing
  Personal Finance
  Renting & Real Estate
  Small Business
  Taxes
Cars & Transportation
  Aircraft
  Boats & Boating
  Car
  Insurance & Registration
  Maintenance & Repairs
  Motorcycles
  Rail
Computers & Internet
  Computer Networking
  Hardware
  Internet
  Programming & Design
  Security
  Software
Consumer Electronics
  Camcorders
  Cameras
  Cell Phones & Plans
  Games & Gear
  Home Theater
  Music & Music Players
  PDAs & Handhelds
  TVs
Dining Out
Education & Reference
  Financial Aid
  Higher Education
  Preschool
  Primary & Secondary Education
  Special Education
  Studying Abroad
  Teaching
Entertainment & Music
  Celebrities
  Comics & Animation
  Horoscopes
  Jokes & Riddles
  Magazines
  Movies
  Music
  Polls & Surveys
  Radio
  Television
Environment
  Alternative Fuel Vehicles
  Conservation
  Global Warming
  Green Living
Family & Relationships
  Family
  Friends
  Marriage & Divorce
  Singles & Dating
  Weddings
Food & Drink
  Beer, Wine & Spirits
  Cooking & Recipes
  Ethnic Cuisine
  Vegetarian & Vegan
Games & Recreation
  Amusement Parks
  Board Games
  Card Games
  Gambling
  Hobbies & Crafts
  Toys
  Video & Online Games
Health
  Alternative Medicine
  Dental
  Diet & Fitness
  Diseases & Conditions
  General Health Care
  Men's Health
  Mental Health
  Optical
  Women's Health
Home & Garden
  Cleaning & Laundry
  Decorating & Remodeling
  Do It Yourself (DIY)
  Garden & Landscape
  Maintenance & Repairs
Local Businesses
News & Events
  Current Events
  Media & Journalism
Pets
Politics & Government
  Civic Participation
  Elections
  Embassies & Consulates
  Government
  Immigration
  International Organizations
  Law & Ethics
  Military
  Politics
Pregnancy & Parenting
  Adolescent
  Adoption
  Baby Names
  Newborn & Baby
  Parenting
  Pregnancy
  Toddler & Preschooler
  Trying to Conceive
Science & Mathematics
  Agriculture
  Astronomy & Space
  Biology
  Botany
  Chemistry
  Earth Sciences & Geology
  Engineering
  Geography
  Mathematics
  Medicine
  Physics
  Weather
  Zoology
Social Science
  Anthropology
  Dream Interpretation
  Economics
  Gender Studies
  Psychology
  Sociology
Society & Culture
  Community Service
  Cultures & Groups
  Etiquette
  Holidays
  Languages
  Mythology & Folklore
  Religion & Spirituality
  Royalty
Sports
Travel

Online Now    Online Now

Author Login    Author Login

Welcome Guest! Please login or create an account.

Username:

Password:



Navigation    Navigation

ADS    Featured Author

ad

ADSDisclosure

an assembly language program to evaluate the sum of the first five numbers?

Author :

Submitted : 2018-06-15 15:11:11    Popularity:     

Tags: program  language  assembly  numbers  sum  

This question is very broad since there's so many types of assembly languages... but just for fun... Here's some Zilog Z80 assembly code. It will take in

Answers:

This question is very broad since there's so many types of assembly languages... but just for fun...

Here's some Zilog Z80 assembly code.
It will take in two inputs: BC and HL. BC is a pointer to the the buffer we want to sum. HL is the number of values we want to sum. It then returns DE, which contains our summation. You'd sum just the first 5 elements by passing 5 into HL.

---------------------------------------...
;Input:
; BC (pointer to buffer)
; HL (length of buffer)
;Output:
; DE (summation)
sum:
ld de, 0
sum_loop:
;Add the current element and increment the pointer
push hl
ld a, (bc)
inc bc
ld h, 0
ld l, a
add hl, de
ex de, hl
pop hl

;Decrement our length and loop if not zero
dec hl
xor a
cp h
jp nz, sum_loop
cp l
jp nz, sum_loop

ret
---------------------------------------...

It all depends on the Assembly (or Assembler) language yu are using. For which processor family? Do your numbers start at 0 or 1 - or do you men the first five numbers that happen to be in some array?

You don t get it, do you? Or you just forgot the details?

Are you asking about a general solution or are you looking for a solution for a specific type of computer. Different computers have different Assembler languages. Next you have to decide whether to use a native compiler (that runs on the target machine) or one of the cross compilers (that run on different computers).

The general way I would set it up is

load immediate or literal value of 0 into register 0
clear register 1
label1:
add into register 1, register 0
increment register 0
compare register 0 with the immediate value of 5, if it is less, then jump or branch back to label1
at this point, the sum will be in register 1

Depending on the definition of what "the first five numbers" means, the program may need to be adjusted. Do the first 5 numbers start with 0 or 1? Or is it some array or list of numbers stored in memory somewhere?

Without knowing your target architecture, no one can give a more detailed program, but the above can be adapted to most architectures (for example, in x86, register 0 would be al, ax, eax, or rax). I suggest you take a crack at it, then if you have trouble, post your code, and people can help. It's important to try, however poorly, first. Most people have trouble with assembly on their first try - I did.

IBM S/360 Assembler (*not* assembly):

. . . . . . . LA . . . 1,0
. . . . . . . LA . . . 2,5
LOOP .. AR . . . 1, 2
. . . . . . . BCT . . 2,LOOP
* Register 1 now has 5+4+3+2+1 = 15 in it.

If you're using x86 assembler, there's a LOOP instruction you can use to follow the same pattern, but the counter (register 2 above) must be in the CX/ECX/RCX register for 16/32/64-bit code. Like the 360/370 "Branch On Count" (BCT) instruction above, it's only good for "do-while" type loops, that run at least once. If zero iterations are possible, you can add a conditional branch-around ("if-then") before the loop.

Good one Billy-Bob.
Here's one in PIC assembly, wiith comments to show what is being calculated:

; The ram address of 'i1' (byte) is 0x028
; The ram address of 'i2' (byte) is 0x029
; 4: i1 = 0
CLRF 0x028 ;set i1 total to zero
; 5: For i2 = 1 To 5
MOVLW 0x01
MOVWF 0x029 ; Initialize loop counter i2 to = 1 and store it
L0002:
MOVF 0x029,W ;In loop, read i2 and see if it is over 5 yet
SUBLW 0x05
BTFSS STATUS,C
GOTO L0003 ;Yes, i2 is over 5, go to end of program
; 6: i1 = i1 + i2
MOVF 0x028,W ;move existing value of i1 to W register
ADDWF 0x029,W ;Add i2 to W register (values of 1 to 5)
MOVWF 0x028 ;save new total back in i1 location
; 7: Next i2
MOVLW 0x01
ADDWF 0x029,F ;Increment loop counter by one
BTFSS STATUS,C
GOTO L0002 ;Go back and add next number
L0003:
; 8: End

OK, I assume you're using Intel 8008 assembly language?

XRA
LBI 005
LCI 001
loop: ADC
INC
DCB
JFZ loop
HLT

And your question is ... ? Or were you hoping that someone would do your homework for you? I charge $100 an hour, or any fraction thereof, and if it's a time-sensitive or top priority, I add an additional 15% to the total. But when you go on your first job interview, and they want you to demonstrate your programming skills, THEN what will you do? (Yes, I have actually seen questions on this forum asking for help on a job interview!). And if you ever get a job (highly unlikely at the rate you're going), will you want someone to come down and do your work for you while you get paid?

If you want help, you get started, and then as you have specific questions, ask your question. Remember to show all your work.

But if you can't even get started, it's time to drop that class and take up something else, such as basket weaving!

But don't ask others to help you cheat by doing your homework for you while you get a grade you don't deserve and didn't earn!



Good
Back Homepage
Back


Article Source:
www.Aphotolog.Com

Answer Questions