Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Two 8086 Assembly Language Questions..

1 view
Skip to first unread message

Madhumita

unread,
Oct 30, 2003, 2:59:09 AM10/30/03
to
Two 8086 Assembly Language Questions..

Hi Friends,

can anyone help me with this : I am unable to do my 2nd Sem
assignments ..

1>Write a 8086 assembly language subroutine that can be used for
passward matching.

Interface/call this subroutine from a C program.

2>Write a program in 8086 assembly language that accept two floating
point numbers from the screen in format:

ddddEsee

where,

dddd are four decimal digits

E is exponent symbol

s is sign

ee contains exponent value.

A decimal is assumed prior to four decimal digits.For example a number
45 in the above format will be:4500E+02.The program adds the two
numbers if the exponent value is same,otherwise issues an error
message"Exponent does not match".


Thanks,

Madhumita

R.Wieser

unread,
Oct 30, 2003, 7:08:41 AM10/30/03
to
Madhumita <madhum...@yahoo.co.in> schreef in berichtnieuws
e128276e.03102...@posting.google.com...

> Two 8086 Assembly Language Questions..
>
> Hi Friends,
>
> can anyone help me with this : I am unable to do my 2nd Sem
> assignments ..

[Snip]

It's nice you've shown us the specifications of your assignments, but what
do you expect from us ? I for one can't really help you, as you have not
specified any problems ...

Or did you mean that we should supply you with full-blown solutions ? If
that's so, you expect us to help you to obtain your grades by cheating, and
I, for one, am not really willing to do so ....

In short : Show us your code, and specify what problems you have with it.
That way we can point you to mistakes in coding, as well as in the approach
to the problem. But *you* will have to do the work. :-)

Regards,
Rudy Wieser


Madhumita

unread,
Oct 31, 2003, 1:17:25 AM10/31/03
to
Hi Friends,

can anyone help me with this : Please check if it i s correct.

1>Write a 8086 assembly language subroutine that can be used for
passward matching.

Interface/call this subroutine from a C program.

Here is my solution :

;ALGORITHM :

=> Initialise variables
=> accept password
=> check password
=> If password correct then display message
"You are allowed to access all facilities"
else display "Please try again"


;REGISTERS : Uses CS, DS, ES, AX, DX, CX, SI, DI

DATA SEGMENT

PASSWORD DB 'FAILSAFE' ; Source String

PASSWORD DB 'FEELSAFE' ; Destination String

MESSAGE DB 'You are allowed to access all facilities'

MESSAGE1 DB 'Please try again'


DATA ENDS

CODE SEGMENT

ASSUME CS : CODE, DS : DATA, ES : DATA

MOV AX, DATA

MOV DX, AX ; Initialise data segment register ; as destination
string is
; considered to be in extra
; segment

LEA SI, PASSWORD ; Load source pointer

LEA DI, DESTSTR ; Load destination pointer

MOV CX, 08 ; Load counter with string length

CLD ; Clear direction flag

REPE CMPSB ; Compare the 2 strings
; byte by byte

JNE NOTEQUAL ; If not equal, jump to
; NOTEQUAL

MOV AH, 09 ;else display message

MOV DX, OFFSET MESSAGE;

INT 21h ; Display the message

NOTEQUAL : MOV AX,4C00h ; interrupt function to halt

INT 21h

CODE ENDS

END START


__________________________________________________________________


The above code can be written in C and interfaced with parameter
passing as
follows:


PUBLIC PASSWD

.MODEL small, C

.CODE

PASSWD PROC switch : word


MOV AX, DATA

MOV DX, AX ; Initialise data segment register ; as destination
string is
; considered to be in extra
; segment

LEA SI, PASSWORD ; Load source pointer

LEA DI, DESTSTR ; Load destination pointer

MOV CX, 08 ; Load counter with string length

CLD ; Clear direction flag

REPE CMPSB ; Compare the 2 strings
; byte by byte

JNE NOTEQUAL ; If not equal, jump to
; NOTEQUAL

MOV AH, 09 ;else display message

MOV DX, OFFSET MESSAGE;

INT 21h ; Display the message

NOTEQUAL : MOV AX,4C00h ; interrupt function to halt

INT 21h

PASSWD ENDP

END

The C program to test the above code is as follows

#include<stdio.h>

int passwd(char pass[]);

main()

{
char pass[8];
int val=0;

printf("Enter password:");
scanf("%s" , pass);
fflush(stdin);

val = passwd(pass);

if(val=0)
printf("Please try again...");
else
printf("You are allowed to access all facilities...");

}

int passwd(char *s1)
{

char pass1[]= {"FAILSAFE"};
char pass2[]= {"FEELSAFE"};

char *s2, *s3;
s2=pass1;
s3=pass2;

printf("Checking Password.........");

while((*s1 == *s2) || (*s1 == *s3))
{
if((*s1 == '\0') || (*s2 == '\0') || (*s3 == '\0'))
return (0);

s1++;
s2++;
s3++;

}

return (1);
}


I am unable to find a solution for the following :

R.Wieser

unread,
Oct 31, 2003, 5:08:36 AM10/31/03
to

Madhumita <madhum...@yahoo.co.in> schreef in berichtnieuws
e128276e.03103...@posting.google.com...
> Hi Friends,

Hello Madhumita,

> can anyone help me with this : Please check if it is correct.


>
> 1>Write a 8086 assembly language subroutine that can be used for
> passward matching.
>
> Interface/call this subroutine from a C program.
>
> Here is my solution :
>
> ;ALGORITHM :
>
> => Initialise variables
> => accept password
> => check password
> => If password correct then display message
> "You are allowed to access all facilities"
> else display "Please try again"
>
>
> ;REGISTERS : Uses CS, DS, ES, AX, DX, CX, SI, DI
>
> DATA SEGMENT
>
> PASSWORD DB 'FAILSAFE' ; Source String
> PASSWORD DB 'FEELSAFE' ; Destination String

duplicate label PASSWORD ...

> MESSAGE DB 'You are allowed to access all facilities'
> MESSAGE1 DB 'Please try again'

Unused MESSAGE1

> DATA ENDS
>
> CODE SEGMENT
>
> ASSUME CS : CODE, DS : DATA, ES : DATA
>
> MOV AX, DATA
>
> MOV DX, AX ; Initialise data segment register ; as destination
> ; string is considered to be in extra segment
>
> LEA SI, PASSWORD ; Load source pointer
> LEA DI, DESTSTR ; Load destination pointer

Label DESTSTR not present ...

> MOV CX, 08 ; Load counter with string length

What would happen if either of the two, above defined, passwords
to-be-compared-with would not equal 8 chars ?

> CLD ; Clear direction flag
> REPE CMPSB ; Compare the 2 strings byte by byte
>
> JNE NOTEQUAL ; If not equal, jump to NOTEQUAL
>
> MOV AH, 09 ;else display message
> MOV DX, OFFSET MESSAGE;
> INT 21h ; Display the message
>
> NOTEQUAL : MOV AX,4C00h ; interrupt function to halt
> INT 21h
>
> CODE ENDS
>
> END START

I'm afraid that the above won't do what you expect from it. Just an
observation : You've defined two passwords, but only seem to check the first
one (which is quite different than what you wrote in your C function)

> __________________________________________________________________
>
> The above code can be written in C and interfaced with parameter
> passing as
> follows:
>
>
> PUBLIC PASSWD
>
> .MODEL small, C

Jep. You nailed the C calling-convention here :-)

> .CODE
>
> PASSWD PROC switch : word

You define an argument here, named "switch". Alas, you're not using it
anywhere :-\

> MOV AX, DATA

The label DATA is undefined in your routine ... Where does it come from ?

> MOV DX, AX
> ; Initialise data segment register as destination
> ; string is considered to be in extra segment
>
> LEA SI, PASSWORD ; Load source pointer
> LEA DI, DESTSTR ; Load destination pointer
> MOV CX, 08 ; Load counter with string length
> CLD ; Clear direction flag
> REPE CMPSB ; Compare the 2 strings byte by byte
> JNE NOTEQUAL ; If not equal, jump to NOTEQUAL
>
> MOV AH, 09 ;else display message
> MOV DX, OFFSET MESSAGE;
> INT 21h ; Display the message

So, you display a message that the password is good (what password ? I did
not enter a password !), but then just keep on going, right into the
"notequal" bit ...

> NOTEQUAL : MOV AX,4C00h ; interrupt function to halt
> INT 21h
>
> PASSWD ENDP
>
> END
>
> The C program to test the above code is as follows

[Snip]

I'm sorry, but the C program is, in most way's, not equal to your
Assembly-function ...

And, if you excuse me for saying so, you're actually *not testing* anything.
You may prove with the C program that your C password-function works, but it
does not say anything about the working of your Assembly-function ...

> val = passwd(pass);

You're transferring an argument to the "passwd" routine (the password to be
checked), and in return get a value indicating if the password matches.
Your Assembly-routine does not do anything with the passed argument (named
"switch"), nor does it return a value (it aborts the program if the password
does not match).

> if((*s1 == '\0') || (*s2 == '\0') || (*s3 == '\0'))

Here you're checking if both passwords ended on the same character, but in
the Assembly-routine you're just loading the length of both (!) strings :


"MOV CX, 08 ; Load counter with string length"

Just a few questions :
What would happen if someone wanted to change one of the two passwords
("failsafe" & "feelsafe"), so they're of a different length ?
What would happen if you would want to add a third (or fourth) password to
the list ?

I'm going to stop here, as it's enough to keep you busy for a few hours :-)

Regards,
Rudy Wieser


Frank Kotler

unread,
Oct 31, 2003, 7:20:51 AM10/31/03
to
Madhumita wrote:
> Hi Friends,
>
> can anyone help me with this : Please check if it i s correct.
>
> 1>Write a 8086 assembly language subroutine that can be used for
> passward matching.
>
> Interface/call this subroutine from a C program.
>
> Here is my solution :
>
> ;ALGORITHM :
>
> => Initialise variables
> => accept password

You might want to write a custom "password input" routine for this, that
just shows "********" on the screen(?).

> => check password
> => If password correct then display message
> "You are allowed to access all facilities"
> else display "Please try again"
>
>
> ;REGISTERS : Uses CS, DS, ES, AX, DX, CX, SI, DI
>
> DATA SEGMENT
>
> PASSWORD DB 'FAILSAFE' ; Source String
>
> PASSWORD DB 'FEELSAFE' ; Destination String

You want different names here - I assume that's just a typo...

> MESSAGE DB 'You are allowed to access all facilities'
>
> MESSAGE1 DB 'Please try again'

If you're displaying these with int 21h/9, they'll want to be terminated
with '$'. You going to let them re-try indefinitely? If not, you might
want a "retries" variable, and a third message, "The FBI is being sent
to your house. Connection terminated" :)

> DATA ENDS
>
> CODE SEGMENT
>
> ASSUME CS : CODE, DS : DATA, ES : DATA
>
> MOV AX, DATA
>
> MOV DX, AX ; Initialise data segment register ; as destination
> string is
> ; considered to be in extra
> ; segment

Couple problems here - you want ds, not dx (probably just a typo). Also,
you mention "extra segment", but don't actually do the "mov es, ax".

> LEA SI, PASSWORD ; Load source pointer
>
> LEA DI, DESTSTR ; Load destination pointer
>
> MOV CX, 08 ; Load counter with string length

Not so great to limit the length to 8 characters...

> CLD ; Clear direction flag

Good! I always forget to do this.

> REPE CMPSB ; Compare the 2 strings
> ; byte by byte
>
> JNE NOTEQUAL ; If not equal, jump to
> ; NOTEQUAL
>
> MOV AH, 09 ;else display message
>
> MOV DX, OFFSET MESSAGE;
>
> INT 21h ; Display the message

When you add the "try again" message, you'll want to jump over it from here.

> NOTEQUAL : MOV AX,4C00h ; interrupt function to halt
>
> INT 21h
>
> CODE ENDS
>
> END START
>
>
>
>
> __________________________________________________________________
>
>
> The above code can be written in C and interfaced with parameter
> passing as
> follows:
>
>
> PUBLIC PASSWD

Might want _PASSWD...

> .MODEL small, C
>
> .CODE
>
> PASSWD PROC switch : word

"switch" might be a confusing name for a variable...

> MOV AX, DATA
>
> MOV DX, AX ; Initialise data segment register ; as destination
> string is
> ; considered to be in extra
> ; segment
>
> LEA SI, PASSWORD ; Load source pointer
>
> LEA DI, DESTSTR ; Load destination pointer

What happened to "switch"?

> MOV CX, 08 ; Load counter with string length

Might want to make the length to compare a parameter to this function,
or use zero-terminated strings...

> CLD ; Clear direction flag
>
> REPE CMPSB ; Compare the 2 strings
> ; byte by byte
>
> JNE NOTEQUAL ; If not equal, jump to
> ; NOTEQUAL
>
> MOV AH, 09 ;else display message
>
> MOV DX, OFFSET MESSAGE;
>
> INT 21h ; Display the message
>
> NOTEQUAL : MOV AX,4C00h ; interrupt function to halt
>
> INT 21h

Surely you want to "ret", not quit, from a called function!

> PASSWD ENDP
>
> END
>
>
> The C program to test the above code is as follows
>
> #include<stdio.h>
>
> int passwd(char pass[]);
>
> main()
>
> {
> char pass[8];
> int val=0;
>
> printf("Enter password:");
> scanf("%s" , pass);
> fflush(stdin);
>
> val = passwd(pass);

I'm not good at C, but I think you might have a problem here - "pass" is
an array, I think you might want a pointer to it here.

> if(val=0)
> printf("Please try again...");
>
> else
> printf("You are allowed to access all facilities...");
>
> }
>
> int passwd(char *s1)
> {
>
> char pass1[]= {"FAILSAFE"};
> char pass2[]= {"FEELSAFE"};
>
> char *s2, *s3;
> s2=pass1;
> s3=pass2;
>
> printf("Checking Password.........");
>
> while((*s1 == *s2) || (*s1 == *s3))
> {
> if((*s1 == '\0') || (*s2 == '\0') || (*s3 == '\0'))
> return (0);
>
> s1++;
> s2++;
> s3++;
>
> }
>
> return (1);
> }

I thought you were going to call the asm function?

> I am unable to find a solution for the following :
>
>
> 2>Write a program in 8086 assembly language that accept two floating
> point numbers from the screen in format:
>
> ddddEsee
>
> where,
>
> dddd are four decimal digits
>
> E is exponent symbol
>
> s is sign
>
> ee contains exponent value.
>
> A decimal is assumed prior to four decimal digits.For example a number
> 45 in the above format will be:4500E+02.The program adds the two
> numbers if the exponent value is same,otherwise issues an error
> message"Exponent does not match".

This is kind of a weird one, alright. FPU programming is kinda hard for
a beginner, but these aren't the usual floating point numbers. I suppose
you find the 'E' ('e' allowed too?), and compare what comes after it
just as in the password program. If there's a mismatch, we're off the
hook - just do the error message. If the exponents match, just add the
mantissas. Do you know how to do that part? (keeping in mind that we're
working with strings, not numbers?) What about an "overflow"? If the
numbers are 5500E+02 and 5500E+02, the result would be 11000E+02 - we're
probably supposed to make that 1100E+3, no? PITA! This doen't seem like
a very well thought out assignment to me. Well, you can get started with
it - display a prompt, get the two strings (from the *screen*???), find
the 'E' ("invalid format" if it's not there, I guess), and compare the
exponents. I don't know if it would be easier to convert the substrings
representing the mantissa to numbers or write an ascii addition routine.
The problem is that 1 + 1 = 2, but '1' + '1' != '2'! And '2' + 1 = '3',
but '9' + 1 isn't going to print '10'! Especially if you're expected to
"normalize" 11000E+02 to 1100E+03, it's probably easier to convert the
substrings to numbers, add 'em, convert back to ascii string, and then
output the result in the proper format.

I hope that one isn't due for a couple weeks!

Best,
Frank

Matt Taylor

unread,
Oct 31, 2003, 7:38:50 AM10/31/03
to
"Frank Kotler" <fbko...@comcast.net> wrote in message
news:3FA253A3...@comcast.net...
<snip>

> > main()
> >
> > {
> > char pass[8];
> > int val=0;
> >
> > printf("Enter password:");
> > scanf("%s" , pass);
> > fflush(stdin);
> >
> > val = passwd(pass);
>
> I'm not good at C, but I think you might have a problem here - "pass" is
> an array, I think you might want a pointer to it here.
<snip>

In ANSI C, pass == &pass. This almost *always* comes up when someone
declares a global array in C and tries to access it from assembly or vice
versa. C programmers tend to forget that a pointer and an array are not the
same thing despite the compiler treating them (nearly) identically.

The above fragment is correct, although fflush(stdin) seems a bit useless.

-Matt


T.M. Sommers

unread,
Nov 1, 2003, 6:55:24 AM11/1/03
to

fflush(stdin) actually invokes undefined behavior, so the
fragment is not correct.


Madhumita

unread,
Nov 2, 2003, 11:51:33 PM11/2/03
to
"R.Wieser" <rwieser-...@xs4all.nl> wrote in message news:<3fa23680$0$149$e4fe...@dreader5.news.xs4all.nl>...

> Madhumita <madhum...@yahoo.co.in> schreef in berichtnieuws
> e128276e.03103...@posting.google.com...
> > Hi Friends,
>
Thanks Rudy for your helpful comments..I'll take care of your suggestions..

Charles A. Crayne

unread,
Nov 3, 2003, 12:35:33 AM11/3/03
to
On 03 Nov 2003 01:51:02 +0200
Phil Carmody <thefatphi...@yahoo.co.uk> wrote:

:Are you sure? A quick read of n869 (Feb 1999, latest I have here)
:seems to indicate it's more likely to be implementation defined,
:but I can't see explicitly why it has to be undefined behaviour.
:J.2's rider on fflush might not always apply.

As a former computer design engineer, I consider the difference between
"implementation defined" and "undefined" to be nothing more than whether or
not the decision was documented. In neither case does it equate to being
random.

-- Chuck

Phil Carmody

unread,
Nov 2, 2003, 6:51:02 PM11/2/03
to
"T.M. Sommers" <tm...@mail.ptd.net> writes:
>
> fflush(stdin) actually invokes undefined behavior, so the fragment is
> not correct.
>

Are you sure? A quick read of n869 (Feb 1999, latest I have here)


seems to indicate it's more likely to be implementation defined,
but I can't see explicitly why it has to be undefined behaviour.
J.2's rider on fflush might not always apply.

Phil
--
Unpatched IE vulnerability: Click hijacking
Description: Pointing IE mouse events at non-IE/system windows
Reference: http://safecenter.net/liudieyu/HijackClick/HijackClick-Content.HTM
Exploit: http://safecenter.net/liudieyu/HijackClick/HijackClick2-MyPage.HTM

T.M. Sommers

unread,
Nov 3, 2003, 5:23:47 AM11/3/03
to
Phil Carmody wrote:
> "T.M. Sommers" <tm...@mail.ptd.net> writes:
>
>>fflush(stdin) actually invokes undefined behavior, so the fragment is
>>not correct.
>
> Are you sure? A quick read of n869 (Feb 1999, latest I have here)
> seems to indicate it's more likely to be implementation defined,
> but I can't see explicitly why it has to be undefined behaviour.
> J.2's rider on fflush might not always apply.

Section 7.19.5.2 says for fflush:

If stream points to an output stream or an update stream in which
the most recent operation was not input, the fflush function
causes any unwritten data for that stream to be delivered to the
host environment to be written to the file; otherwise, the
behavior is undefined.


Phil Carmody

unread,
Nov 3, 2003, 8:42:28 AM11/3/03
to
"T.M. Sommers" <tm...@mail.ptd.net> writes:

Exactly. It doesn't mention stdin.
It mentions (the complement of) input streams, or update streams most
recently used for input.

However, you can freopen stdin (the standard explicitly mentions that
the typical use of freopen is for std{in,out,err}), and I can see
nothing that indicates that stdin can't be reopened as an update
stream, apart from the rider in the description of freopen that
says that the behaviour of changing the mode is implementation defined.
Of course, you must follow the most-recently-used clauses peppered
around the in stdio.h descriptions in order for usage of the new stdin
to be valid, but if you do that, I can see no explicit reason why
occasional use of stdin as an output stream, and therefore fflushing
it, isn't valid. (I basically checked every reference to 'stdin' in
the document.)

Phil
--
Unpatched IE vulnerability: Timed history injection
Description: cross-domain scripting, cookie/data/identity theft, command execution
Reference: http://safecenter.net/liudieyu/BackMyParent2/BackMyParent2-Content.HTM
Exploit: http://www.safecenter.net/liudieyu/BackMyParent2/BackMyParent2-MyPage.HTM

0 new messages