Go Back  DVD Talk Forum > General Discussions > Tech Talk
Reload this Page >

help with basic, basic assembly language

Tech Talk Discuss PC Hardware, Software, Internet and Other Technology

help with basic, basic assembly language

Old 03-27-06, 05:43 PM
  #1  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
help with basic, basic assembly language

X db "HELLOWORLD$"

mov cx, 5
mov bx, offset X
mov al, 20H

ABC: add [bx], al
inc bx
Loop ABC
mov ah, 9
mov dx,offset X
int 21h

what is the ouput?

i don't really get the offset lines and the add [bx], al line anyone care to explain? the book has 1 paragraph on offset and it's just making me more confused.
Old 03-27-06, 11:11 PM
  #2  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
wow so none of you know anything? dangit
Old 03-27-06, 11:32 PM
  #3  
DVD Talk Hall of Fame
 
Join Date: Apr 2002
Location: Philadelphia
Posts: 8,572
Likes: 0
Received 0 Likes on 0 Posts
ok according to my notes from my assembly class, the offset command returns the value of the string. This is then sent to dx to give the interrupt command the address to print the string.
Old 03-28-06, 09:50 AM
  #4  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
thanks. cx is a counter im assuming, is the output the first 5 characters? this is from a sample midterm and i'm 99% sure my teacher would do something tricky in there to make it so it's more than just printing out the entire string.
Old 03-28-06, 10:18 AM
  #5  
Senior Member
 
Join Date: Sep 2002
Posts: 916
Likes: 0
Received 0 Likes on 0 Posts
it's hard to help because we dont know what your registers are. im assuming you got your b, c, d 8-bit registers. and A is your 16-bit accumulator (guessing from the al and ah, a low and a high). instruction sets may differ so what does the book tell you about the keyword offset?
Old 03-28-06, 11:40 AM
  #6  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
the book says the offset operator returns the offset (distance, in bytes) of a data label.

the example is
mov esi, offset bVal ; esi = 00404000
mov esi, offset wVal ; esi = 00404001

which just makes me even more confused.

this is for intel chipsets if that helps.

my example is the entire question i have on my paper so im not sure what you mean by not knowing what they are. this is from the first test of the first class in assembly/computer architecture so i'm pretty new to all this.
Old 03-28-06, 11:48 AM
  #7  
DVD Talk Hall of Fame
 
Join Date: Apr 2002
Location: Philadelphia
Posts: 8,572
Likes: 0
Received 0 Likes on 0 Posts
20 hex (20H) is 32 decimal. The ASCII value of 32 is a space. Basically, this program iterates through the string replacing characters with a space. It prints out a string of spaces.

There are 10 characters in HELLOWORLD, so there should be 10 spaces.
Old 03-28-06, 11:59 AM
  #8  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
thanks.

what does

mov cx, 5 do? is it just there to confuse me?
Old 03-28-06, 12:01 PM
  #9  
DVD Talk Hall of Fame
 
Join Date: Apr 2002
Location: Philadelphia
Posts: 8,572
Likes: 0
Received 0 Likes on 0 Posts
cx should be used as the counter. For the loop? I compiled the code and all I got was a blank line. So, I am not sure if I am right or not (probably not). But at least you have something more to work with.
Old 03-28-06, 12:07 PM
  #10  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
yea i thought it was a counter too, but if it just prints a blank line i'm just wondering why it's there, like it puts 5 spaces in there and prints out WORLD or something. thanks for your help.
Old 03-28-06, 12:10 PM
  #11  
DVD Talk Legend
 
Join Date: Apr 2002
Posts: 20,726
Likes: 0
Received 0 Likes on 0 Posts
And I thought my C programming class was hard.
Old 03-28-06, 04:14 PM
  #12  
Senior Member
 
Join Date: Sep 2002
Posts: 916
Likes: 0
Received 0 Likes on 0 Posts
in a motorolla processor, mov cx, 5 would load 5 into the c register and add [bx], al would be bx = bx + al. i dont know if that helps.
Old 03-28-06, 05:43 PM
  #13  
DVD Talk Hall of Fame
 
andicus's Avatar
 
Join Date: Dec 2004
Location: Canada
Posts: 8,063
Received 4 Likes on 4 Posts
Originally Posted by nodoubt
in a motorolla processor, mov cx, 5 would load 5 into the c register and add [bx], al would be bx = bx + al. i dont know if that helps.
I would've guessed that the add [bx], al was an indirect addressing mode that would cause al to be added to the location contained in bx, as opposed to bx itself. Or would that be add (bx), al ?

My guess is that it's not 'changing' the string to spaces, but that it's adding 32 to each character, resulting in changing the characters to lower case.

I'm not sure how the looping construct works, i.e. what determines that it's done, since I don't see any conditional branching. I guess it's a macro, and judging by the loading of 5 into cx, and it's lack of use anywhere else, I'm guessing you would loop 5 times, so the output would be:

helloWORLD

Although, I don't know what:

mov ah, 9
mov dx,offset X
int 21h

does, so it may be indicating a length of 9, so maybe it will only output:

helloWORL ? Or does that mean it'll output bytes 0-9? You'll have to figure that out.

*edit* just looked up the 21h interrupt, and 9 tells it to display the string up until it finds the $ terminator, so I'll go back to the output being:

helloWORLD

Last edited by andicus; 03-28-06 at 05:51 PM.
Old 03-28-06, 08:08 PM
  #14  
DVD Talk Hall of Fame
 
Join Date: Apr 2002
Location: Philadelphia
Posts: 8,572
Likes: 0
Received 0 Likes on 0 Posts
Andicus,

Your solution makes the most sense and is definitely the answer. Thanks for figuring that out. I was never too good at assembler (as shown by my piss poor answer), but I was still curious about the answer to this one.
Old 03-28-06, 08:24 PM
  #15  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
thanks for the responses, just got back from taking my midterm, and of course theree was nothing like that on the test, but i appreciate your help, it's going to help me with the lab coming up anyway. Assembly language sucks ass btw.
Old 03-28-06, 08:34 PM
  #16  
JM
DVD Talk Special Edition
 
Join Date: Dec 1999
Posts: 1,156
Likes: 0
Received 0 Likes on 0 Posts
Originally Posted by andicus
I'm not sure how the looping construct works, i.e. what determines that it's done, since I don't see any conditional branching. I guess it's a macro, and judging by the loading of 5 into cx, and it's lack of use anywhere else, I'm guessing you would loop 5 times, so the output would be:
The LOOP instruction decrements the counter register (cx) and jumps to the target if the counter is not 0--i.e. it will simply loop for the number of times equal to to cx. For the OP, I highly recommend you check out the Art of Assembly by Randall Hyde. It is available online in HTML and PDF here: http://webster.cs.ucr.edu/

You can also purchase it in book format.
Old 03-28-06, 08:39 PM
  #17  
X
Administrator
 
X's Avatar
 
Join Date: Oct 1987
Location: AA-
Posts: 10,763
Likes: 0
Received 4 Likes on 3 Posts
Originally Posted by DVDKrayzie
Assembly language sucks ass btw.
I used to love assembly language. It was satisfying entering it right into the computer from my head and then stepping through its statements. Don't get much of a chance to use it anymore unless I'm decompiling something.
Old 03-28-06, 08:49 PM
  #18  
DVD Talk Gold Edition
Thread Starter
 
Join Date: Mar 2000
Location: NorCal
Posts: 2,927
Likes: 0
Received 0 Likes on 0 Posts
Originally Posted by JM
The LOOP instruction decrements the counter register (cx) and jumps to the target if the counter is not 0--i.e. it will simply loop for the number of times equal to to cx. For the OP, I highly recommend you check out the Art of Assembly by Randall Hyde. It is available online in HTML and PDF here: http://webster.cs.ucr.edu/

You can also purchase it in book format.

thanks im going to look into it, i don't think my textbook was written by a human.
Old 03-28-06, 10:59 PM
  #19  
DVD Talk Hall of Fame
 
andicus's Avatar
 
Join Date: Dec 2004
Location: Canada
Posts: 8,063
Received 4 Likes on 4 Posts
Originally Posted by DVDKrayzie
thanks for the responses, just got back from taking my midterm, and of course theree was nothing like that on the test, but i appreciate your help, it's going to help me with the lab coming up anyway. Assembly language sucks ass btw.
Hehe... Isn't that always the way?

Assembly was cool, back in the early days. You just have to learn the basics, and then it's pretty straightforward.

JM, thanks for the explanation!

It was interesting to look at this type of stuff again. It's been, errr... a while.

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 On
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Thread Tools
Search this Thread

Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service - Do Not Sell My Personal Information

Copyright 2018 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.