Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
Question
Book Icon
Chapter 4, Problem 4.48HW
Program Plan Intro

Given Y86-64 code:

.pos 0

 irmovq stack, %rsp

 call main

 halt

.align 8

data:

  .quad 0x0000000000000004

  .quad 0x0000000000000003

  .quad 0x0000000000000002

data_end:

  .quad 0x0000000000000001

main:

  irmovq data,%rdi

  irmovq data_end,%rsi

  call ysBubbleP

  ret

ysBubbleP:

  jmp L2

L4:

  mrmovq 8(%rax), %r9

  mrmovq (%rax), %r10

  rrmovq %r9, %r8

  subq %r10, %r8

  jge L3

  rmmovq %r10, 8(%rax)

  rmmovq %r9, (%rax)

L3:

  irmovq $8, %r8

  addq %r8, %rax

  jmp L5

L6:

  rrmovq %rdi, %rax

L5:

  rrmovq %rsi, %r8

  subq %rax, %r8

  jg L4

  irmovq $8, %r8

  subq %r8, %rsi

L2:

  rrmovq %rsi, %r8

  subq %rdi, %r8

  jg L6

    ret

.pos 0x200

stack:

Data movement instructions:

  • The different instructions are been grouped as “instruction classes”.
  • The instructions in a class performs same operation but with different sizes of operand.
  • The “Mov” class denotes data movement instructions that copy data from a source location to a destination.
  • The class has 4 instructions that includes:
    • movb:
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 1 byte data size.
    • movw: 
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 2 bytes data size.
    • movl:
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 4 bytes data size.
    • movq:
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 8 bytes data size.

Unary and Binary Operations:

  • The details of unary operations includes:
    • The single operand functions as both source as well as destination.
    • It can either be a memory location or a register.
    • The instruction “incq” causes 8 byte element on stack top to be incremented.
    • The instruction “decq” causes 8 byte element on stack top to be decremented.
  • The details of binary operations includes:
    • The first operand denotes the source.
    • The second operand works as both source as well as destination.
    • The first operand can either be an immediate value, memory location or register.
    • The second operand can either be a register or a memory location.

Jump Instruction:

  • The “jump” instruction causes execution to switch to an entirely new position in program.
  • The “label” indicates jump destinations in assembly code.
  • The “je” instruction denotes “jump if equal” or “jump if zero”.
    • The comparison operation is performed.
    • If result of comparison is either equal or zero, then jump operation takes place.
  • The “ja” instruction denotes “jump if above”.
    • The comparison operation is performed.
    • If result of comparison is greater, then jump operation takes place.
  • The “pop” instruction resumes execution of jump instruction.
  • The “jmpq” instruction jumps to given address. It denotes a direct jump.

Blurred answer
Students have asked these similar questions
Consider the following code fragment.Trace the code and for each iteration of the while loop write the updated values of x and y. What does this code finally print out on lines 10 and 11?
PLEASE ASSIST ON THE BELOW REVIEW Before the user can read an email, they have to see the emails. To achieve this, your program should first of all determine which emails have not been read and return that to the user. Then the user can choose. The emails should be numbered so that the user can provide the number as the index. Consider using the enumerate function to achieve this. I realise that there are no emails within the email box , kindly add some dummy emails in this list so that at least there is something within the inbox list.Do the same for marks as spam. Present to the user all the emails that have not been marked as spam for the user to mark as spam.Most importantly, your code is not well indented. Try to work on your indentation as it makes your code easier to read and the logic easier to follow. Indentation is key in python to define the blocks of statements. The number of spaces must be uniform in a block of code. It is preferred to use four whitespaces instead of tabs…
Experiment 1: IMPLEMENTATION OF CAESAR CIPHER Objective: To implement the simple substitution technique named Caesar cipher using C+ language. Theory: To enerypt a message with a Caesar cipher, each letter in the message is changed using a simple rule: shift by three. Each letter of the message is shifted a fixed distance (3 for example) down the alphabet, A becomes D, B becomes E, and so on. For the last letters, we can think of alphabet as a circle and "wrap around", W becomes Z. X becomes A, Y becomes B, and Z becomes C. To change a message back, cach letter is replaced by the one three before it. Example ABCDEFGHIJKLMNOPQRSTUVWXYZ t t t t t t t t ttt t t t t t t tt t t t t t t ft DEFGHIJKLMNOPQRSTUVW XY Z ABc) digorithm STEP-1: Read the plain text from the user. STEP-2: Read the key value from the user. STEP-3: If the key is positive then encrypt the text by adding the key with each character in the plain text. STEP-4: Else subtract the key from the plain text. STEP-5: Display the…

Chapter 4 Solutions

Computer Systems: A Programmer's Perspective (3rd Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning