Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PLEASE HELP need assembly to store AA in current data segment???????

Status
Not open for further replies.

luv88dj

Programmer
Dec 3, 2003
4
US
ok, I am so totally LOST on this - I am taking a class right now and the current assignment is to do the following: "write an assembly language program to store AA (10101010) in the whole contents of the current data segment." That is all of the direction that was given on the assignment. We have been going over this stuff for a couple weeks now and I am STILL completely lost on this assembly stuff - is there someone out there who can help me out with this? I don't know where to start and even if I did I am sure I wouldn't know how to finish it! PLEASE HELP - Thanks!
 
what is AA?

Ion Filipski
1c.bmp
 
Are we OK to assume you're in dos for IBM-compatible PC and not in protected mode?
 
I really wish I could be more clear on this - as for what AA is I have no idea - like I said, I am really new to this and I do not understand it one bit! I can say that yes we are using DOS for an IBM compatible PC and not in protected mode. Unfortunately I couldn't tell the difference between 0xAA or 0AAh or AA so as I said I really can't be more clear. This is supposed to be an introductory hardware class - you know, putting all the physical parts of a computer together and turning it on to see if it boots. I understand if it is not clear enough for further help, but I do appreciate you all trying! Thanks
 
ok, I did that and it worked - is that definitely storing AA in the WHOLE contents of the CURRENT data segment? It's not that I don't trust you, it's just that that seems so simple and I really thought it would be a lot more complicated than that.
 
It means you will is value AA as data segment. Why AA? I don't know, it could be any other value...

Ion Filipski
1c.bmp
 
No, I don't think that was the aim at all.

For reasons best known to your lecturer, I think they want you to store the hexadecimal number 0aah in all the memory accessible using the ds data segment register as the segment register.

There are a number of things with which you seem to be having trouble.

(1) hexadecimal numbers. So that the assembler recognises them, it expects a 0 on the start to indicate that it's a number of some sort (rather than a few letters), and the h on the end indicates hexadecimal. Default is decimal, so 099 will be taken as 99 decimal, while 099h will be understood as hexadecimal, (9*16)+9. If you aren't happy with hexadecimal, base 16 counting, find the appendix in a good assembler textbook.

(2) Memory addressing. In non-protected mode all memory addresses have a segment and an offset. The segment is actually simply shifted left 4 bits (= multiplied by 16) and added to the offset to create a 20-bit address which corresponds to 1Mbyte of memory, the DOS-addressable space (of which only about 500K is for programs. The rest is operating system/screen/etc space.
The segment bit is what's held in cs, ds, es. The offset can be in various registers or just a number, so when you do
mov myvariable, ax
what you are doing is putting the contents of ax into memory location addressed by ds:constant, where constant is the offset the assembler is using for your variable 'myvariable'.

(3) Filling the whole data segment with 0aah. This means putting 0aah in every byte accessible by ds. To address lots of locations like this, you probably want to use an instruction like
mov ds:si, al
where the al register already contains the value 0aah. You need to loop this instruction for all possible values of si.

But, important but, you (probably) cannot do this in real life. Your lecturer has set you a question whose answer cannot be tested. And that is something I find deplorable. All programs should be tested, and to encourage a student to do otherwise is a bad act! This sort of exercise is to be frowned upon!

The reason you can't do it in real life is you have no way to know how much of the data segment is available for your data, and how much already contains useful things. In some cases the data segment might actually overlap with the code segment (e.g. in com applications they're the same). Or it might overlap with the stack. Either would cause catastrophic disaster if things were overwritten.

It is never a good idea to write to memory whose function you do not know.

Good luck!
 
Thank you very much for all of your help! I was concerned about overwriting something that shouldn't be overwritten. This was not an assignment that the instructor had planned out (meaning he tested it himself beforehand), he just made it up on the fly in class. I can't understand why he would have done this, he seems to really know a lot about this ssembly stuff, so it is a good question why he would give us something that couldn't truly be tested. I have asked him to clarify all of this for me and I will see what he comes back with. Thank you all again, I realize I am no expert (HA not even close) but maybe I understood it better than I thought I did - at least some of it.

 
Sorry, I shouldn't undermine people like that. It's just assignments like that get to me sometimes, but there again, things I've tried to think up on the fly often haven't been the best either. You are certainly right to thing about overwriting, and if that leads to a profitable discussion between you and your instructor, then his assignment will have done something useful for the class.
Have fun!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top