Help for a friend

Associate
Joined
12 Jan 2005
Posts
161
Location
South East. Slough. Berks
Hi all, first of all im sorry for creating a thread like this but i couldnt really help my friend with this so i thought id ask here.

He needs some help on creating a Machine code using DOS that adds up the decimals 43+54 and displays the answer on the screen as a single character. It should scan the keyboard and if you press "n" the program should display my name.

If i press x then the program should return me back to the DOS prompt. If any other key is pressed then it should rescan keyboard.

Thanks a lot
 
OK, here's a few links I've just dug up that will be useful for this task:
http://heim.ifi.uio.no/~stanisls/helppc/int_21.html
http://www.geocities.com/SiliconValley/2072/asm.htm
http://burks.bton.ac.uk/burks/language/asm/asmtut/asm3.htm
http://burks.bton.ac.uk/burks/language/asm/asmtut/asm5.htm#need

Also, here's a partial solution I've just concocted, hopefully that gets you going (you must type stuff that is bold, italics are comments or other instructions that must NOT be typed) :

Code:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>[B]debug[/B]
-[B]n foo.com[/B]  [I]// set the name of the output file[/I]
-[B]a 100[/B] [I]// start entering assembly instructions at offset 100 (standard entrypoint offset for .com files[/I]
1536:0100 [B]mov ax, 43[/B]
1536:0103 [B]add ax, 54[/B] [I]// add 54 to 43, and put in ax[/I]
1536:0106 [B]mov bx, ax[/B] [I]// copy ax to bx[/I]
1536:0108 [B]mov ah, 2[/B]  
1536:010A [B]mov dl, al[/B] 
1536:010C [B]int 21h[/B]  [I]// int21,2 = output char (held in dl)[/I]
1536:010E [B]mov ah, 7[/B]
1536:0110 [B]int 21h[/B] [I]// int 21,7 = wait for input key (non-echo.) [/I]
1536:0112 [I]<press enter>[/I]
-[B]rcx[/B] [I]// directly modify contents or register cx (rcx), which is length of program bytes  [/I]
CX 0000
:[B]12[/B]  [I]// entered code is 12 bytes, so set to 12[/I]
-[B]w[/B] [I]// write to disk[/I]
Writing 00012 bytes
-[B]q[/B]  

C:\>[B]dir foo.com[/B]
 Volume in drive C has no label.
 Volume Serial Number is 7E8C-3E78

 Directory of C:\

24/03/2006  02:22                18 FOO.COM
               1 File(s)             18 bytes
               0 Dir(s)  44,504,686,592 bytes free

C:\>

Refer to the DOS Int21 (and other interrupts) reference to see how to do other types of input and output etc. and use the other assembly instructions like "cmp" and "je"/"jne" and so on to compare and conditionally jump after having done your comparson etc. You might want to use a better assembler than "debug" as well, but it had the benefit here of being included with Windows and allowing me to illustrate the above with no complications (I didn't have anything else handy....) :)
 
Last edited:
Back
Top Bottom