VenkatKaushal
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Lab 4 Name: T.Venkat Kaushal Roll No.: CS22B058 --- ## Question 1 **Code** ```assembly= .data .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 .text #address add x1 x0 x0 lui x1 0x10000 addi x1 x1 0x000 #s: x2 addi x2 x0 3 #i: x3 addi x3 x0 10 for_loop_1: blt x3 x0 end_loop_1 lw x4 0(x1) addi x1 x1 4 add x2 x2 x4 addi x3 x3 -1 j for_loop_1 end_loop_1: li a7 10 ecall ``` **Observation:** This is where you will write your observations * The answer is stored in the register x2 --- ## Question 2 **Code** ```assembly= .data .word 1, 3, 4, 2, 4 str1: .string "true" str2: .string "false" .text #initialized address addi x1 x0 0 lui x1 0x10000 addi x1 x1 0x000 #size: x2 addi x2 x0 5 #count: x3 addi x3 x0 0 #i : x4 addi x4 x4 0 for_loop_1: bge x4 x2 end_loop_1 # condition for loop lw x5 0(x1) #load word if_1: andi x6 x5 1 # x6 contains 0 or 1 addi x7 x0 1 # x7 = 1 bne x6 x7 end_if_1 # condition x6 == 1 addi x3 x3 1 # count++ if_2: addi x8 x0 3 bne x3 x8 end_if_2 addi x9 x0 1 addi x4 x4 1 addi x1 x1 4 j end_loop_1 end_if_1: addi x3 x0 0 # count = 0 j if_2 end_if_2: addi x9 x0 0 addi x4 x4 1 addi x1 x1 4 j for_loop_1 end_loop_1: add x0 x0 x0 beq x9 x7 print_true la a0 str2 li a7 4 ecall li a7 10 ecall print_true: la a0 str1 li a7 4 ecall li a7 10 ecall ``` **Observation:** * The answer is displayed in the console. --- ## Question 3 **Code** ```assembly= .data .word 1 2 3 4 5 6 .text #initialized the address(1 - n) add x1 x0 x0 lui x1 0x10000 addi x1, x1, 0x000 #size:x2 = n addi x2 x0 3 #initialized the address(n - 2n) add x3 x0 x0 lui x3 0x10000 #x4 = 2n slli x4 x2 2 add x3 x3 x4 #initialized the address add x31 x0 x0 lui x31 0x10000 slli x10 x2 1 slli x5 x10 2 add x31 x31 x5 #i:x6 addi x6 x0 0 #j:x7 add x7 x0 x2 for_loop_1: bge x6 x2 end_loop_1 bge x7 x4 end_loop_1 lw x8 0(x1) sw x8 0(x31) addi x1 x1 4 addi x31 x31 4 lw x9 0(x3) sw x9 0(x31) addi x3 x3 4 addi x31 x31 4 addi x7 x7 1 addi x6 x6 1 j for_loop_1 end_loop_1: li a7 10 ecall ``` **Observation:** * See the memory in Ripes, the content is present in data section after the address next to the end of last element address. --- ## Question 4 **Question:* **Two Sum**: Given an vector, and a target, return indexes of two elements in the vector whose sums equals target. Assume the answer exist always. **Code** ```assembly= .data .word 3 2 4 .text #address add x1 x0 x0 lui x1 0x10000 addi x1 x1 0x000 #target: x2 add x2 x0 x0 addi x2 x2 6 #i: x3 addi x3 x0 0 #size: x4 addi x4 x0 3 for_loop_1: bge x3 x4 end_loop_1 #j: x5 addi x5 x3 1 for_loop_2: bge x5 x4 end_loop_2 #condition slli x6 x3 2 slli x7 x5 2 add x8 x6 x1 add x9 x7 x1 lw x10 0(x8) lw x11 0(x9) add x12 x10 x11 bne x12 x2 end_if_1 li a7 10 ecall end_if_1: addi x5 x5 1 j for_loop_2 end_loop_2: addi x3 x3 1 j for_loop_1 end_loop_1: li a7 10 ecall ``` **Observation:** * The indexes are(i, j) , located in the registers x3,x5 respectively, those should be returned. --- ## Question 5 **PseudoCode** ```assembly= .data node_struct: .word 0 // Value to be stored in the data .word 0 // Pointer to the next node init_linkedlist: addi x1 x0 0 la x1, node_struct // Allocating memory for head node sw zero 0(x1) // Store value in the head node sw zero 4(x1) // Store next pointer in the head node mv x2 x1 // Save head pointer, and let other pointer points it. ret insert_at_end: mv x3 x2 // Load LinkedList la x1, node_struct // Allocating new node addi x5 x0 5 // memory to be inserted mv x4 x5 // Load memory to be inserted sw x4 , 0(x1) // Store value in the node sw zero, 4(x1) // Store next pointer in the new node(NULL) traverse_loop: lw x6, 4(x3) // Load next pointer beqz x6, insert_done // If next pointer is NULL , exit loop mv x3, x6 // move to next node j traverse_loop insert_done: mv x6, x1 // Update last node's next to point to the new node sw x3, 4(x2) ret print_loop: lw x1, 0(t1) // Load the value of the current node jal ra, print_function // we can write a print function as we traverse lw x2, 4(x2) // load next pointer bnez x2, print_loop // if next node, if not NULL, repeat loop ret ``` **Observation:** 1. We can simulate the working of the linked list to an extent using RISC-V assembly language and Ripes. --- ## Question 6 **Observation:** 1. When malloc() allocates the block, it allocates extra bytes to hold an integer containing the size of the block. 2. This integer is located at the beginning of the block; the address actually returned to the caller points to the location just past this length value. 3. When a block is placed on the (doubly linked) free list, free() uses the bytes of the block itself in order to add the block to the list. Reference: "The Linux Programming Interface" Textbook. ---

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully