GIDForums  

Go Back   GIDForums > Computer Programming Forums > Assembly Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Sep-2007, 19:44
Widgets Widgets is offline
New Member
 
Join Date: Sep 2007
Posts: 11
Widgets is on a distinguished road

Address errors with assembly language?


first off here is my code:

page 60,132
TITLE HMWK6-13 (EXE) Chapter 6
;----------------------------------------------------------
.MODEL SMALL
.STACK 64 ;Define stack
.DATA ;Define data
BYTE1 DB 11 ;BH
BYTE2 DB 15 ;FH
WORD3 DW 0
;----------------------------------------------------------
.CODE ;Define code segment
MAIN PROC FAR
MOV AL,BYTE1 ;move BYTE1 to AL
ADD AL,BYTE2 ;add contents of BYTE2 to AL
MOV DL,42H ;move the value of 42H to DL
XCHG DL,AL ;exchange the contents of AL and DL
MUL DL ;multiply the contents of AL by DL
MOV WORD3, AX ;transfer the product from AX to WORD3
INT 21H
MAIN ENDP ;End of procedure
END MAIN ;End of program

My issue is withe BYTE1, BYTE2 and WORD3. When i run DEBUG it shows my first command to be:
MOV AL,[0002]
which is fine but the value that i set BYTE1 equal to is in [0012] so AL is set to FF.

As far as i can tell the code is right, but a second set of eyes may find my error.

Any help would be great. Thanks.
  #2  
Old 28-Sep-2007, 12:31
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Address errors with assembly language?


When I assembled your code (with tasm32) into an object file, here's what the listing showed
Code:
1 ;---------------------------------------------------------- 2 0000 .MODEL SMALL 3 0000 .STACK 64 ;Define stack 4 0000 .DATA ;Define data 5 0000 0B BYTE1 DB 11 ;BH 6 0001 0F BYTE2 DB 15 ;FH 7 0002 0000 WORD3 DW 0 8 ;---------------------------------------------------------- 9 0004 .CODE ;Define code segment 10 0000 MAIN PROC FAR 11 0000 A0 0000r MOV AL,BYTE1 ;move BYTE1 to AL 12 0003 02 06 0001r ADD AL,BYTE2 ;add contents of BYTE2 to AL 13 0007 B2 42 MOV DL,42H ;move the value of 42H to DL 14 0009 86 D0 XCHG DL,AL ;exchange the contents of AL and DL 15 000B F6 E2 MUL DL ;multiply the contents of AL by DL 16 000D A3 0002r MOV WORD3, AX ;transfer the product from AX to WORD3 17 0010 CD 21 INT 21H 18 0012 MAIN ENDP ;End of procedure 19 END MAIN ;End of program
So, as far as I can tell, your code does what you expect.

When I unassembled the .obj file with DEBUG, here's what I got:

Code:
0CA5:01BB A00000 MOV AL,[0000] 0CA5:01BE 02060100 ADD AL,[0001] 0CA5:01C2 B242 MOV DL,42 0CA5:01C4 86D0 XCHG DL,AL 0CA5:01C6 F6E2 MUL DL 0CA5:01C8 A30200 MOV [0002],AX 0CA5:01CB CD21 INT 21

Again, it looks to me as if can do what you had in mind.

A few points:


1. I used Borland tasm32. I don't know what you used.

2. I just assembled it into an obj file. I couldn't execute the program on windows XP even if I had an executable, and I don't have an instruction set simulator for 80xx code.

3. I inspected the object file (by "eyeball" from a hex dump) to find where the actual code started in the file.

4. I started the Windows debug program from a command line. Then, knowing where the instructions started (at 0xbb in the .obj file), I entered the following:

u 01bb

(Since the object file is loaded by default at 0100 of whatever segment it is using.)


If you are using another assembler or another procedure for assembling or another debugger or another procedure for debugging/disassembling, I doubt that I can help. In particular, I don't have a platform on which I could execute (or otherwise test) that program even if I had the correct executable.

Good Luck!

Regards,

Dave

"That's all I can do --- I can't do no more!"
---Popeye, the Sailor Man
  #3  
Old 28-Sep-2007, 15:06
Widgets Widgets is offline
New Member
 
Join Date: Sep 2007
Posts: 11
Widgets is on a distinguished road

Re: Address errors with assembly language?


How do you look at the .obj file? I am running vista and it wont let me use notepad to read it legibly.

I use MASM611 to assemble and link and then use DEBUG (embedded in windows) to look at the registers and it shows nothing in registers [0000] - [0002]. But since it runs how it is suppose to i will be happy with that for now.

Thanks for your help Dave.
  #4  
Old 28-Sep-2007, 16:36
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Address errors with assembly language?


Quote:
Originally Posted by Widgets
How do you look at the .obj file?

I use vim for editing (gvim, actually) on Linux and Windows XP platforms.
Vim is either supplied with or available for all Linux distributions that I have ever seen, and is upward compatible with "vi", which has been ubiquitous with UNIX since System V. (In Linux, when you enter "vi" on the command line you get vim. At least that's what I get.)

It is a powerful productivity tool, but not exactly intuitive. It took me the better part of a day (yes, almost all day) to get comfortable with vi (about a hundred years ago, it seems), but the graphical version, gvim, has scroll bars, drop-down menus, etc., that make learning elementary operations pretty simple. (There is also a built-in tutorial and an extensive built-in help system.)

Extra features abound, and, in conjunction with a program named xxd (supplied with vim), you can use vim as an editor of binary files as well as text files. just get into vim (or gvim), then enter:

:%! xxd -g1

Windows versions of vim and gvim can be downloaded from many places on the web. I would just start at the home page: http://www.vim.org/

Of course, there are zillions of programs called "dump" or "hexdump" or some such thing that you can find on the web that let you look the contents of files in some binary mode. There are also a number of "hex editors" that allow you to inspect and edit contents of binary files. I use vim because it's there and I already use it as my main programming text editor.

I'm thinking that if you are going to be doing any assembly language programming (even if it's just a little bit for a class), you might want to check some of them out.

Regards,

Dave
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembly Language alcoholic Assembly Language 2 28-Aug-2007 15:05
Assemblers & assembly language BlueFireCO. Assembly Language 2 26-Mar-2007 09:56
Pointer Usage in C++: Beginner to Advanced varunhome C++ Forum 0 19-Aug-2005 09:25
which language ? onauc C++ Forum 2 19-Nov-2004 02:53

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:53.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.