Akshatha
    • 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: AKSHATHA.R.H Roll No.: CS22B003 --- ## Question 1 ```assembly= .data .word 8 3 1 7 3 3 9 0 9 6 1 base: .word 0x10000000 str1: .string " " str2: .string "\n" .text lw x1,base li x2,11 # int i=11 li x4,0 # i=0 li x2,3 # int s=3 li x5,4 li x10, 0x10000000 Loop1: beq x4,x3,main lw x6,0(s1) add a0,x6,x0 li a7 1 ecall la a0 str1 li a7 4 ecall addi x4,x4,1 addi x10,x10,4 j Loop1 main: li x4,0 # i=0 Loop2: beq x3,x4,End lw x11,40(x1) add x11,x11,x2 sw x11,40(x7) sub x7,x7,x5 addi x3,x3,-1 j Loop2 End: la a0 str2 li a7 4 ecall li x10, 0x10000000 li x3,11 li x4,0 Loop3: beq x4,x3,Exit lw x6,0(x10) add a0,x6,x0 li a7 1 ecall la a0 str1 li a7 4 ecall addi x4,x4,1 addi x10,x10,4 j Loop3 Exit: li a7 10 ``` --- ## Question 2 ```assembly= .data arr: .word 7,6,5,4,3,2,1 str: .string "True" str1: .string "False" .text la x1 arr addi x2 x0 6 #x2 is n addi x3 x0 1 #x3 0 addi x20 x0 1 #and with addi x21 x0 0 #counter addi x11 x0 3 loop: beq x3 x2 exit addi x2 x2 -1 lw x4 0(x1) addi x1 x1 4 andi x5 x4 1 beq x5 x20 count addi x21 x0 0 count: addi x21 x21 1 beq x21 x11 exit2 j loop exit: la a0 str1 li a7 4 exit2: la a0 str li a7 4 ecall ``` --- ## Question 3 ```assembly= .data arr: .word 1,2,3,4,5,6,7,8 base: .word 0x10000000 arr1: .word 0,0,0,0 arr2: .word 0,0,0,0 str2: .string " " .text lw x1,base la x2,arr2 la x12,arr2 la x18,arr1 la x19,arr1 addi x3,x0,4 addi x4,x0,0 addi x21,x0,0 addi x22,x0,0 addi x5,x0,4 Loop: beq x3,x4,exit1 lw x6,0(x1) sw x6,0(x18) addi x18,x18,4 addi x1,x1,4 addi x4,x4,1 j Loop exit1: beq x21,x5,exit lw x7,0(x1) sw x7,0(x12) addi x12,x12,4 addi x21,x21,1 addi x1,x1,4 j exit1 exit: beq x22,x5,exit2 lw x27,0(x19) addi a0,x27,0 li a7,1 ecall la a0,str2 li a7,4 ecall addi x19,x19,4 lw x28,0(x2) addi a0,x28,0 li a7,1 ecall la a0,str2 li a7,4 ecall addi x2,x2,4 addi x22,x22,1 j exit exit2: addi a7,x0,10 ecall ``` --- ## Question 4 ```assembly= **TWO SUM QUESTION ** .data .word 2,4,6,8,1,3,5,9 base: .word 0x10000000 comma: .string "," .text lw x2,base li x5,0 # i=0 li x3,9 li x10,13 # target=13 li x4,0 i: beq x5,x3,exit addi x4,x5,1 addi x5,x5,1 lw x6,0(x2) addi x2,x2,4 add x11,x2,x0 sub x6,x10,x6 j: beq x4,x3,i lw x12,0(x11) addi x11,x11,4 beq x6,x12,success addi x4,x4,1 j j success: sub x6,x10,x12 add x10,x6,x0 li a7 1 ecall addi a7 x0 4 la a0 comma ecall add x10,x12,x0 li a7 1 ecall addi a7 x0 10 ecall exit: addi a7 x0 10 ecall ``` --- ## QUESTION 5 Several steps are involved in the RISC-V assembly language linked list implementation algorithm: Define a node's structure, which has a data field and a pointer to the node after it. Setting the start pointer to null or a sentinel node is a common way to initialize a linked list. The process of inserting a new node at the beginning of the list involves allocating memory for it, setting its data field, updating its next pointer to point to the list's current start, and then updating the start pointer to point to the new node. Execute a traversal loop that begins at the beginning of the list, processes each node (printing or manipulating data, for example), and then advances to the next node until the list's end is reached. --- ## QUESTION 6 a) There should be a pointer to the user-allocated memory block that the free() function may access. b)First, we should essentially retain the memory blocks' state (e.g., whether they are allocated or free). This needs to be completed during the allocation and deallocation phases. During allocation, we need to mark certain blocks as occupied (maybe using a flag or something similar). and we must release it throughout the deallocation process. c)Thus, we can set this block's status to free once we obtain its pointer. d)In addition, after using frre on the memories, we must keep a record of each one. so that we can utilize that for allocation after first verifying in this list that the necessary conditions are satisfied. e)Thus, we can add that memory block to the list of all previously frozen memories after using free on a specific memory.

    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