...

View Full Version : Debug



Stowelly
03-15-2004, 04:34 PM
hi all im new...... just got a little problem making a small program in debug which adds a number in AX and BX and puts them in DX

when it adds the 2 numbers the result is a hex number

also im trying to put into a memory location the difference between the 2 numbers which i do not have a clue how to do.

heres the code i am using so far

debug

a 100

dw 28
dw 16
enter


-a 108
MOV AX,[100]
MOV BX,[102]
ADD DX,AX
ADD DX,BX
MOV DX,[104]

(formatted to show exactly how i do it)

thanks for your help :D

A1ien51
03-15-2004, 04:49 PM
It might help people saying what language you are trying to do this in

Stowelly
03-15-2004, 04:50 PM
sorry. im using MS-Dos debug

Unit
03-16-2004, 03:57 AM
Whoa!

I am unable to offer any help, but I could not resist my amusement at someone trying to do some work in MSDOS!

I used to be a MSDOS pro long back.. now I seem to have lost all touch with it. I can safely blame all the high level languages that are popular now :p

good luck with your program!

Oh, by the way, its called assembly language

Stowelly
03-16-2004, 11:50 AM
lol. trust me mate i wouldnt be using dos if i had another choice..... unfortunately my uni course has decided to make me use dos for it

Unit
03-16-2004, 07:43 PM
alright, i finally recollected enough to get a debug session going :)

addition


-a
0B2A:0100 jmp 120
0B2A:0102 dw 28
0B2A:0104 dw 16
0B2A:0106
-a 120
0B2A:0120 mov ax,[102]
0B2A:0123 mov bx,[104]
0B2A:0127 add dx,ax
0B2A:0129 add dx,bx
0B2A:012B mov [106],dx
0B2A:012F
-g =100

Program terminated normally
-d
0B2A:0100 EB 1E 28 00 16 00 3E 00-A1 00 01 8B 1E 02 01 01 ..(...>.........
0B2A:0110 C2 01 DA 8B 16 04 01 F8-C3 AA 41 FE 34 00 19 0B ..........A.4...
0B2A:0120 A1 02 01 8B 1E 04 01 01-C2 01 DA 89 16 06 01 2D ...............-
0B2A:0130 91 2E 89 36 2F 91 FC 2E-89 0E 94 90 2E C7 06 96 ...6/...........
0B2A:0140 90 00 00 2E C7 06 A9 90-00 00 2E C7 06 9A 90 00 ................
0B2A:0150 00 2E C7 06 66 91 5B 5D-2E C7 06 68 91 7C 3C 2E ....f.[]...h.|<.
0B2A:0160 C7 06 6A 91 3E 2B 2E C7-06 6C 91 3D 3B E8 83 09 ..j.>+...l.=;...
0B2A:0170 73 13 B8 FF FF 53 26 8B-1D 26 3A 0F 73 03 B8 02 s....S&..&:.s...



subtraction


-a 120
0B2A:0120 MOV AX,[0102]
0B2A:0123 MOV BX,[0104]
0B2A:0127 MOV DX,AX
0B2A:0129 SUB DX,BX
0B2A:012B MOV [0106],DX

-d 100
0B2A:0100 EB 1E 28 00 16 00 12 00-A1 00 01 8B 1E 02 01 01 ..(.............
0B2A:0110 C2 01 DA 8B 16 04 01 F8-C3 AA 41 FE 34 00 19 0B ..........A.4...
0B2A:0120 A1 02 01 8B 1E 04 01 89-C2 29 DA 89 16 06 01 2D .........).....-
0B2A:0130 91 2E 89 36 2F 91 FC 2E-89 0E 94 90 2E C7 06 96 ...6/...........
0B2A:0140 90 00 00 2E C7 06 A9 90-00 00 2E C7 06 9A 90 00 ................
0B2A:0150 00 2E C7 06 66 91 5B 5D-2E C7 06 68 91 7C 3C 2E ....f.[]...h.|<.
0B2A:0160 C7 06 6A 91 3E 2B 2E C7-06 6C 91 3D 3B E8 83 09 ..j.>+...l.=;...
0B2A:0170 73 13 B8 FF FF 53 26 8B-1D 26 3A 0F 73 03 B8 02 s....S&..&:.s...



let me know if you need explanation for anything. would be glad to explain what's going on.

Stowelly
03-18-2004, 11:32 AM
sorry just one more small thing. is there another way to find the difference between the two numbers. as im not sure how subtract will work if the first number is less than the number you are subtracting from it

Unit
03-18-2004, 07:29 PM
It will work just fine - SUB instruction is capable of dealing with any numbers.

lets take your example again and reverse the numbers. so we subtract 0x28 from 0x16. if we do the math ourselves, we can see that the result should be 0xFFEE = -18 (this is how negative numbers look like in hex)

A little background on 2's complement notation of integers:
http://www.cs.ualberta.ca/~casey/c101/101notes/2comp.html

so, for 0xFFEE = 1111 1111 1110 1110
note that the most significant bit is 1 - which tells us that it is a negative number.

if you convert this to decimal you will see that it is -18 which indeed is the result of subtracting 0x28(40) from 0x16(22)

now, if you look at the memory location, you will see this


-d 100
0B2A:0100 EB 1E 16 00 28 00 EE FF-B8 01 00 D3 E0 0B E8 59 ....(..........Y
0B2A:0110 5F 07 B0 00 AA 5F 9D F8-C3 AA 41 FE 34 00 19 0B _...._....A.4...

Note that it is written backwards, just like the numbers we started with.

hope that cleared up somethings about subtraction.

Stowelly
03-19-2004, 01:32 PM
thanks alot mate been a big help



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum