Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Program in 8086 having 2 subroutines?

vijendravijendra Posts: 23Member
Two subroutines in 8086:

First for encrypting upper case alphabets in a string as follows:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Q W E R T Y U I O P A S D F G H J K L Z X C V B N M

use XLAT instruction.
The Second subroutine can decrypt the string so obtained.

Now have to write a prog in C which call this function.

Vijendra

Comments

  • blipblip Posts: 756Member
    Okay, according to any x86 instruction reference online you will find that XLAT effectively does AL = [BX + AL] which is perfect for mapping characters to others like for character set translation e.g. EBCDIC to ASCII and back. The easiest solution would be to create two data tables and the separate encryption and decryption routines. I don't forsee any problems with implementation of the core ideas here.

    Making the functions C callable is a tad more difficult as you have to conform to the calling convention. Say you have a function call:
    [blue]EncryptedChar = Encrypt ( Character );[/blue]
    When the C code calls your code, it pushes the parameters in reverse order (doesn't matter in this case as you only have one argument) and then CALLs your function. So the stack looks like this by the time control is passed to you:
    [code]Character [SP + 4]
    CS [SP + 2]
    IP [SP + 0][/code]
    In 8086 assembly the best way to access [blue]Character[/blue] is to use set BP = SP and reference the stack using BP from there using displacements. Don't forget to PUSH BP before modifying it and POP it before your routine returns. The return value, the encrypted character, will need to be placed in AL.
  • vijendravijendra Posts: 23Member
    : Okay, according to any x86 instruction reference online you will find that XLAT effectively does AL = [BX + AL] which is perfect for mapping characters to others like for character set translation e.g. EBCDIC to ASCII and back. The easiest solution would be to create two data tables and the separate encryption and decryption routines. I don't forsee any problems with implementation of the core ideas here.
    :
    : Making the functions C callable is a tad more difficult as you have to conform to the calling convention. Say you have a function call:
    : [blue]EncryptedChar = Encrypt ( Character );[/blue]
    : When the C code calls your code, it pushes the parameters in reverse order (doesn't matter in this case as you only have one argument) and then CALLs your function. So the stack looks like this by the time control is passed to you:
    : [code]Character [SP + 4]
    : CS [SP + 2]
    : IP [SP + 0][/code]
    : In 8086 assembly the best way to access [blue]Character[/blue] is to use set BP = SP and reference the stack using BP from there using displacements. Don't forget to PUSH BP before modifying it and POP it before your routine returns. The return value, the encrypted character, will need to be placed in AL.
    :


    Hi Logically i can understand the solution but implementation in Assembly is tough for me i am very new.
    I know little of c/c++.I am basically a Java programmer but assembly coding i have to find out then only its possible.
    Can you please provide me the outline, if possible code for execution.

    Thanks
    Vijendra
  • blipblip Posts: 756Member
    Try implementing the entire thing in C. All I can say is make a couple of pre-defined arrays to use as lookup tables, which is important since in the assembly implementation, the actual lookup operations will be done using the XLAT instruction. You practically posted the outline for execution in your initial post so try it for your version in C. I can help you further but I just don't want to give out the code for everything.
Sign In or Register to comment.