Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1289
  • Last Modified:

8086 Assembly Language - Help writing a program

I am using DEBUG through MS-DOS to make and run a certain program.
I need to write a program through DEBUG that will do the following:

1. Input two one digit numbers from keyboard [A and B]
2. Compare the numbers and display "First Larger" or "Second Larger"
3. Add the numbers and display the sum
4. Subtract the smaller from the larger and display the difference
5. Multiply the numbers and display the product
6. Divide the larger number by the smaller and display the quotient..

Now my knowledge of assembly language is very limited, I havent taken a class to learn it yet.
I know how to do the basic things like MOV, ADD, SUB but when it comes to inputting something from the keyboard, storing it, comparing the numbers I am completely clueless...

I have tried searching for help online but it wasnt much help because like I said, I havent had any assembly language  classes. The class that I am taking now is Intel Microprocessor Fundamentals and it only teaches about how microprocessor works, memory, registers, basic assembly commands, addresses, etc...but it doesnt show you how to program anything using assembly.

I really need help with constructing this program.

Thanks in advance
0
webzila
Asked:
webzila
  • 7
  • 6
1 Solution
 
manish_regmiCommented:
hi,
 You can use this link to study assembly in detail.
http://cs.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html

to input digits you can use
int 0x21 ah=01
the value will be in the al register. It is an ascii code. Subtract 0x30 from it to get the number in decimal.

eg.

mov ah, 01h
int 0x21

mov bl, al
mov ah, 01h
int 0x21

you can use the cmp to compare between two values

cmp al, bl

I cannot give you full codes. first try yourself.
we can help you where you feel difficult.

regards manish.



0
 
webzilaAuthor Commented:
Thanks for the link. I have been to that site before and had it bookmarked already. That thing is like an entire book that would take months to learn. You cant really just pick out a section out of it and use it unless you know the things that come before it and I dont...

Here is the problem, I havent had an Assembly Language class yet. I am sure it would be much easier if I did and I would be able to follow the instructions and examples. But the class I am is Intel Microprocessors and only gives the basics of architecture, interfacing and just a brief overview of programming. It only explains the basics to get you ready for the actual assembly programming but doesnt put it all together so that you can actually go out and program something...

Yes, this is an assignment for a class. However the instructor and the lab assistant are not on the same page and have never spoken to each other. We are only learning about the basic commands, types of registers, and how to find physical addresses. And now this guy wants an assembly program.

I tried following the examples but its not working. I have only learned how to do very basic things like load a register with something using MOV, subtract/add/divide registers, and other basic functions. I dont even know how to display these outputs on the screen in a program and I am only able to view the values through DEBUG.

I'll try to figure this out again, but I have alraedy tried for a very long time with no success before asking for help here. Are there any working examples that perform what I asked and not just snippets of code that you have to complete because I really dont know how...thats what the assembly programming class is for I guess.
0
 
webzilaAuthor Commented:
Ok, I found the following program that does part of what I need to do..
http://www.wepin.com/uop/References/assemblyexamples/complete.html

The truth is that I only understand about 10% of the total code in that program..
But anyways, how would I run that in DEBUG. I dont have any assembly compilers...and debug doesnt understand all of those commands in that program..

How would I run that program in DEBUG...is it possible?
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
manish_regmiCommented:
hi,
 I have never used DEBUG for assembly language programming. I don't know how to do it.
You can try NASM. It is a very good assembler and it is free. And also very small file to download.
try it,

http://nasm.sourceforge.net

regards manish.
0
 
manish_regmiCommented:
hi,
 I recommend you not to use the code in the link you gave because it does direct i/o with the vga.
I can give you a simple nasm example for displaying.

;a simple app
segment data
str db 'hello world',0
 
segment stack
 resb 64

segment code

..start:
mov ax, data
mov ds, ax
mov es, ax

;display a string
mov ah, 0x09
lea dx, [str]
int 0x21

; input a character
mov ah, 01h
int 0x21



regards manish

0
 
webzilaAuthor Commented:
Ok, this might sound stupid but how do you run NASM
I created a test program called test.asm
Downloaded the NASM package and followed the instructions to install it.
Then when I try to run it all I get is this:

D:\NASM>nasm -f elf test.asm
Exiting due to signal SIGSEGV
General Protection Fault at eip=0002a997
eax=fffd0100 ebx=0000000f ecx=000002a0 edx=fffd0000 esi=00000100 edi=00000005
ebp=0008bec0 esp=0008beb0 program=
cs: sel=01a7  base=02a00000  limit=7d5effff
ds: sel=01af  base=02a00000  limit=7d5effff
es: sel=01af  base=02a00000  limit=7d5effff
fs: sel=017f  base=00006ee0  limit=0000ffff
gs: sel=01bf  base=00000000  limit=ffffffff
ss: sel=01af  base=02a00000  limit=7d5effff

Call frame traceback EIPs:
  0x0002a997
  0x0002a91d
  0x00029bae
  0x00029c65
0
 
manish_regmiCommented:
hi,
 The code was for dos. U cannot use int 0x21 in linux.
Also u cannot load segment registers in linux.
mov ax, data
mov ds, ax
mov es, ax

Never do this in 32bit os like linux.

Try runnning it dos or windows.

If u want to write assembly programs for linux or other unix. See
www.linuxassembly.org

I dont recommend linux for learning assembly.

Nasm is also available for dos/windows.

regards manish

0
 
webzilaAuthor Commented:
That was in Windows. I am running Win XP
I went to DOS using cmd
I have NASM in C:\Windows\System32

The thing I posted before was my D drive, and I had the nasm.exe in the NASM folder...

Here is another error

C:\>nasm -f elf test.asm
Exiting due to signal SIGSEGV
General Protection Fault at eip=0002a997
eax=fffd0100 ebx=0000000f ecx=000002a0 edx=fffd0000 esi=00000100 edi=00000005
ebp=0008bec0 esp=0008beb0 program=
cs: sel=01a7  base=02a00000  limit=7d5effff
ds: sel=01af  base=02a00000  limit=7d5effff
es: sel=01af  base=02a00000  limit=7d5effff
fs: sel=017f  base=00006ee0  limit=0000ffff
gs: sel=01bf  base=00000000  limit=ffffffff
ss: sel=01af  base=02a00000  limit=7d5effff

Call frame traceback EIPs:
  0x0002a997
  0x0002a91d
  0x00029bae
  0x00029c65

So in the above example, my program is located on C:\
Trying to run anything using NASM results in that thing you see above...I have never used Linux before :)
0
 
manish_regmiCommented:
hi,
 It will be best if u write programs for dos.
Make 16 bit applications.
nasm -f obj xyz.c

You will need a linker also. For 16 bit apps you can use tlink(You have this if u have turbo/borland c) or any other linker.
download from here.
http://community.borland.com/article/0,1410,20841,00.html

regards manish

 
0
 
manish_regmiCommented:
ok,
 So why did you make elf. Elf is format for linux and other unix. For windows make obj and link with a linker.

nasm -f obj -o xyz.obj xyz.asm
tlink xyz.obj

regards manish
0
 
webzilaAuthor Commented:
Well, like I said I have never done this before..so I was just trying to follow an example and the elf command was listed in the sample (in nasm documentation) and it didnt say if its for Linux or Windows...

I must say that this is too much for me. I dont think I can figure this out just yet. The only thing I ve been doing up till now is basic MOV commands with DEBUG just to see how data moves.

Thanks for trying to help anyways..
0
 
webzilaAuthor Commented:
manish_regmi thanks for trying to help me.
This assignment was canceled because the instructor realized that we havent learned this at all yet.

So all we did is load 2 registers with any Hex number we want and then compare, subtract, add, divide, and multiply them as seperate operations and simply print out the results which was really easy..

So my code for ADD was something like:
a 100
MOV AL,2
MOV BL,3
ADD AL,BL
MOV AH,02
MOV DL,AL
INT 21
INT 20

and that was good enough.

Thanks
0
 
webzilaAuthor Commented:
That answer didnt help me at all. None of the answers did. I still tried to give "some" partial points to people who tried to help but did not want to give all the points away due to the fact that I did not get the answer which resolved my problem...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now