Solved

8086 Assembly Language - Help writing a program

Posted on 2004-04-03
15
1,253 Views
Last Modified: 2008-03-03
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
Comment
Question by:webzila
  • 7
  • 6
15 Comments
 
LVL 8

Expert Comment

by:manish_regmi
ID: 10751054
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
 
LVL 1

Author Comment

by:webzila
ID: 10751189
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
 
LVL 1

Author Comment

by:webzila
ID: 10753927
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
 
LVL 8

Expert Comment

by:manish_regmi
ID: 10754369
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
 
LVL 8

Accepted Solution

by:
manish_regmi earned 500 total points
ID: 10754466
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
 
LVL 1

Author Comment

by:webzila
ID: 10755083
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 8

Expert Comment

by:manish_regmi
ID: 10755341
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
 
LVL 1

Author Comment

by:webzila
ID: 10755365
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
 
LVL 8

Expert Comment

by:manish_regmi
ID: 10755385
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
 
LVL 8

Expert Comment

by:manish_regmi
ID: 10755425
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
 
LVL 1

Author Comment

by:webzila
ID: 10757845
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
 
LVL 1

Author Comment

by:webzila
ID: 10772301
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
 
LVL 1

Author Comment

by:webzila
ID: 11122441
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now