Assembly代写:CS204 Assembly Programming

X86指令集下,实现类似C语言的加减乘除计算。

Assembly

64bitAdd

  • All programs must compile without warnings when using the -Wall and -Werror options
  • Submit only the files requested o Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc
  • All input will be valid unless stated otherwise
  • The examples provided in the prompts do not represent all possible input you can receive.
  • All inputs in the examples in the prompt are underlined o You don’t have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
  • If you have questions please post them on CampusWire

Write an assembly program called 64bitAdd.s that adds two 64 bit numbers together.

  1. The first number will be referenced by the label num1 and the second number will be referenced by the label num2.
  2. The upper 32 bits of the sum should be placed in EDX and the lower 32 bits in EAX.
  3. AFTER the last line of code that you wish to be executed in your program please place the label done.
    • Make sure that there is an instruction after the done line and a new line after that instruction. If you don’t your output won’t match mine.
  4. I have included a Makefile for you that will compile your program.
  5. IT IS OF VITAL IMPORTANCE THAT YOU NAME YOUR LABELS AS SPECIFIED AND MAKE THE APPROPRIATE AMOUNT OF SPACE FOR EACH VARIABLE! I will be using gdb to test your code and if your labels do not match then the tests will fail. You must also make sure to include the done label AFTER the last line of code you want executed in your program so that I know where to set break points.
  6. The following table shows how the numbers will be laid out in memory.

div.

Time it took Matthew to complete: 10 mins

  • All programs must compile without warnings when using the -Wall and -Werror options
  • Submit only the files requested o Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc - Your program must match the output exactly to receive credit. o Make sure that all prompts and output match mine exactly. o Easiest way to do this is to copy and paste them
  • All input will be valid unless stated otherwise
  • Print all real numbers to two decimal places unless otherwise stated
  • The examples provided in the prompts do not represent all possible input you can receive.
  • All inputs in the examples in the prompt are underlined o You don’t have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
  • If you have questions please post them on CampusWire

Write a C program called div.c that implements division on two unsigned integers.

  1. Name your executable div.out
  2. You cannot use division in your solution
  3. Arguments should be accepted from the command line
    • The first argument is the dividend
    • The second argument is divisor
  4. Your program should display the quotient and remainder after doing the division
  5. Your program must complete in O(1) (constant) time
    • This is possible because an integer is 32 bits long and so the loop that does the division should not take longer than 32 iterations.
    • Because of this restriction the following solution is not acceptable as it does not meet the O requirements
    • In order to meet the O requirements, you will have to division in base 2 as you would by hand. See these 2 articles for some examples: Dr. Math and Exploring Binary
      • Hint: use bitwise operators
      • The one step that they leave out and one that you normally skip when doing division by hand is checking to see how many times the divisor goes into the dividend for the numbers that contain fewer digits than the divisor.
        • For example: 30 / 15
        • First, we should check how many times does 15 go into 3.
        • Then we check how many times does 15 go into 30, which is 2.
        • So our answer would be 02 R 0

divAssempbly

  • All programs must compile without warnings when using the -Wall and -Werror options
  • Submit only the files requested o Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc - If you have questions please post them on CampusWire

Translate the C program you wrote to do division in constant time into an assembly program called divAssembly.s.

  1. The label for the dividend is dividend
    • 4 bytes of space should be made for the dividend
  2. The label for the divisor is divisor
    • 4 bytes of space should be made for the divisor
  3. Place the quotient in EAX
  4. Place the remainder in EDX
  5. Don’t forget that if you want to shift by a variable amount the shift amount must be placed in CL. Your assembly code won’t work if you try to place it in any other register.
  6. AFTER the last line of code that you wish to be executed in your program please place the label done.
    • Make sure that there is an instruction after the done line and a new line after that instruction. If you don’t your output won’t match mine.S
  7. IT IS OF VITAL IMPORTANCE THAT YOU NAME YOUR LABELS AS SPECIFIED AND MAKE THE APPROPRIATE AMOUNT OF SPACE FOR EACH VARIABLE! I will be using gdb to test your code and if your labels do not match then the tests will fail. You must also make sure to include the done label AFTER the last line of code you want executed in your program so that I know where to set break points.

editDist.

  • All programs must compile without warnings when using the -Wall and -Werror options
  • Submit only the files requested o Do NOT submit folders or compressed files such as .zip, .rar, .tar, .targz, etc
  • All input will be valid unless stated otherwise
  • The examples provided in the prompts do not represent all possible input you can receive.
  • All inputs in the examples in the prompt are underlined
  • You don’t have to make anything underlined it is just there to help you differentiate between what you are supposed to print and what is being given to your program
  • If you have questions please post them on CampusWire

Write an assembly program called editDist.s that calculates the edit distance between 2 strings. You should translate the C code editDist.c, provided in the starter code, to create your solution. An explanation of what edit distance is can be found here while accompanying pseudo code can be found here.

  1. The label for the first string should be string1 and the label for the second string should be string2.
  2. The edit distance between string1 and string2 should be placed in EAX.
  3. For each string please allocate space for 100 bytes.
    • While you must allocate space for 100 bytes in your final submission you will likely find it easier to work with the .string directive for testing and debugging.
  4. AFTER the last line of code that you wish to be executed in your program please place the label done.
    • Make sure that there is an instruction after the done line and a new line after that instruction. If you don’t your output won’t match mine.
  5. I have included a C implementation of the edit distance program. I highly recommend translating this solution into assembly as it will make your life much easier.
    • As a note remember that constants cannot be swapped. Pay careful attention to this in your solution
    • Use subroutines. It makes life easier (in my opinion)
  6. I have included a Makefile that will compile your program. Your program must be able to be compiled by this Makefile when you submit it
  7. IT IS OF VITAL IMPORTANCE THAT YOU NAME YOUR LABELS AS SPECIFIED AND MAKE THE APPROPRIATE AMOUNT OF SPACE FOR EACH VARIABLE! I will be using gdb to test your code and if your labels do not match then the tests will fail. You must also make sure to include the done label AFTER the last line of code you want executed in your program so that I know where to set break points.