Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds basic legv8 snippets #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 208 additions & 0 deletions snippets/legv8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"set register": {
"prefix": "sreg",
"body": ["ADD ${1:Rd}, XZR, ${2:Rm}", "$3"],
"description": "R[1] = R[2]"
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add description for all of them. Also try to make it easy to realize what the command does.

So if the code inserted is something to the effect of ADDI reg, reg, #1, show how to think of it in basic math terms, like reg = reg + 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good comment! It`s implemented

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! In addition to the math part, could you add a small text description? Also, having the description and placeholder text be the same may be useful. Such as:

  "set register": {
    "prefix": "sreg",
    "body": ["ADD ${1:Rd}, XZR, ${2:Rm}", "$3"],
    "description": "Rd = Rm. Set one register (Rd) to the value of another (Rm)."
  }

Thoughts?

"increment register": {
"prefix": "ireg",
"body": ["ADDI ${1:Rd}, ${1}, #${2:Imt}", "$3"],
"description": "R[1] = R[1] + R[2]"
},
"decrement register": {
"prefix": "dreg",
"body": ["SUBI ${1:Rd}, ${1}, #${2:Imt}", "$3"],
"description": "R[1] = R[1] - R[2]"
},

"stack manipulation with 2 registers": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I were to use this, I would expect to be able to to manipulate two registers when using st2. I completely get that there are two being manipulated here since it automatically includes LR. Do you think st2 would be more intuitive if it deals with LR and one custom register or LR and two custom registers?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking the same thing, but like you said I was stuck on the technicality of it since LR is also a register. But I think that being more intuitive is more important!

"prefix": "st2",
"body": [
"// storing registers in stack before changing them",
"SUBI SP, SP, #16 // make room on stack (SP) for 2 registers",
"STUR LR, [SP, #8] // store return adress (LR) of procedure",
"STUR $reg1, [SP, #0] // store $reg1",
"// body of the procedure",
"$body",
"// restoring saved registers from stack",
"LDUR $reg1, [SP, #0] // restore $reg1",
"LDUR LR, [SP, #8] // restore LR",
"ADDI SP, SP, #16 // restore previous space on stack"
],
"description": "use this to save 2 registers in the Stack, including the return address of the procedure (where the procedure was called)"
},
"stack manipulation with 3 registers": {
"prefix": "st3",
"body": [
"// storing registers in stack before changing them",
"SUBI SP, SP, #24 // make room on stack (SP) for 2 registers",
"STUR LR, [SP, #16] // store return adress (LR) of procedure",
"STUR $reg1, [SP, #8] // store $reg1",
"STUR $reg2, [SP, #0] // store $reg2",
"// body of the procedure",
"$body",
"// restoring saved registers from stack",
"LDUR $reg2, [SP, #0] // restore $reg2",
"LDUR $reg1, [SP, #8] // restore $reg1",
"LDUR LR, [SP, #16] // restore LR",
"ADDI SP, SP, #24 // restore previous space on stack"
],
"description": "use this to save 3 registers in the Stack, including the return address of the procedure (where the procedure was called)"
},
"stack manipulation with 4 registers": {
"prefix": "st4",
"body": [
"// storing registers in stack before changing them",
"SUBI SP, SP, #32 // make room on stack (SP) for 2 registers",
"STUR LR, [SP, #24] // store return adress (LR) of procedure",
"STUR $reg1, [SP, #16] // store $reg1",
"STUR $reg2, [SP, #8] // store $reg2",
"STUR $reg3, [SP, #0] // store $reg3",
"// body of the procedure",
"$body",
"// restoring saved registers from stack",
"LDUR $reg3, [SP, #0] // restore $reg3",
"LDUR $reg2, [SP, #8] // restore $reg2",
"LDUR $reg1, [SP, #16] // restore $reg1",
"LDUR LR, [SP, #24] // restore LR",
"ADDI SP, SP, #32 // restore previous space on stack"
],
"description": "use this to save 4 registers in the Stack, including the return address of the procedure (where the procedure was called)"
},
"stack manipulation with 5 registers": {
"prefix": "st5",
"body": [
"// storing registers in stack before changing them",
"SUBI SP, SP, #40 // make room on stack (SP) for 2 registers",
"STUR LR, [SP, #32] // store return adress (LR) of procedure",
"STUR $reg1, [SP, #24] // store $reg1",
"STUR $reg2, [SP, #16] // store $reg2",
"STUR $reg3, [SP, #8] // store $reg3",
"STUR $reg4, [SP, #0] // store $reg4",
"// body of the procedure",
"$body",
"// restoring saved registers from stack",
"LDUR $reg4, [SP, #0] // restore $reg4",
"LDUR $reg3, [SP, #8] // restore $reg3",
"LDUR $reg2, [SP, #16] // restore $reg2",
"LDUR $reg1, [SP, #24] // restore $reg1",
"LDUR LR, [SP, #32] // restore LR",
"ADDI SP, SP, #40 // restore previous space on stack"
],
"description": "use this to save 5 registers in the Stack, including the return address of the procedure (where the procedure was called)"
},
"stack manipulation with 6 registers": {
"prefix": "st6",
"body": [
"// storing registers in stack before changing them",
"SUBI SP, SP, #48 // make room on stack (SP) for 2 registers",
"STUR LR, [SP, #40] // store return adress (LR) of procedure",
"STUR $reg1, [SP, #32] // store $reg1",
"STUR $reg2, [SP, #24] // store $reg2",
"STUR $reg3, [SP, #16] // store $reg3",
"STUR $reg4, [SP, #8] // store $reg4",
"STUR $reg5, [SP, #0] // store $reg5",
"// body of the procedure",
"$body",
"// restoring saved registers from stack",
"LDUR $reg5, [SP, #0] // restore $reg5",
"LDUR $reg4, [SP, #8] // restore $reg4",
"LDUR $reg3, [SP, #16] // restore $reg3",
"LDUR $reg2, [SP, #24] // restore $reg2",
"LDUR $reg1, [SP, #32] // restore $reg1",
"LDUR LR, [SP, #40] // restore LR",
"ADDI SP, SP, #48 // restore previous space on stack"
],
"description": "use this to save 6 registers in the Stack, including the return address of the procedure (where the procedure was called)"
},
"stack manipulation with 7 registers": {
"prefix": "st7",
"body": [
"// storing registers in stack before changing them",
"SUBI SP, SP, #56 // make room on stack (SP) for 2 registers",
"STUR LR, [SP, #48] // store return adress (LR) of procedure",
"STUR $reg1, [SP, #40] // store $reg1",
"STUR $reg2, [SP, #32] // store $reg2",
"STUR $reg3, [SP, #24] // store $reg3",
"STUR $reg4, [SP, #16] // store $reg4",
"STUR $reg5, [SP, #8] // store $reg5",
"STUR $reg6, [SP, #0] // store $reg6",
"// body of the procedure",
"$body",
"// restoring saved registers from stack",
"LDUR $reg6, [SP, #0] // restore $reg6",
"LDUR $reg5, [SP, #8] // restore $reg5",
"LDUR $reg4, [SP, #16] // restore $reg4",
"LDUR $reg3, [SP, #24] // restore $reg3",
"LDUR $reg2, [SP, #32] // restore $reg2",
"LDUR $reg1, [SP, #40] // restore $reg1",
"LDUR LR, [SP, #48] // restore LR",
"ADDI SP, SP, #56 // restore previous space on stack"
],
"description": "use this to save 7 registers in the Stack, including the return address of the procedure (where the procedure was called)"
},
"stack manipulation with 8 registers": {
"prefix": "st8",
"body": [
"// storing registers in stack before changing them",
"SUBI SP, SP, #64 // make room on stack (SP) for 2 registers",
"STUR LR, [SP, #56] // store return adress (LR) of procedure",
"STUR $reg1, [SP, #48] // store $reg1",
"STUR $reg2, [SP, #40] // store $reg2",
"STUR $reg3, [SP, #32] // store $reg3",
"STUR $reg4, [SP, #24] // store $reg4",
"STUR $reg5, [SP, #16] // store $reg5",
"STUR $reg6, [SP, #8] // store $reg6",
"STUR $reg7, [SP, #0] // store $reg7",
"// body of the procedure",
"$body",
"// restoring saved registers from stack",
"LDUR $reg7, [SP, #0] // restore $reg7",
"LDUR $reg6, [SP, #8] // restore $reg6",
"LDUR $reg5, [SP, #16] // restore $reg5",
"LDUR $reg4, [SP, #24] // restore $reg4",
"LDUR $reg3, [SP, #32] // restore $reg3",
"LDUR $reg2, [SP, #40] // restore $reg2",
"LDUR $reg1, [SP, #48] // restore $reg1",
"LDUR LR, [SP, #56] // restore LR",
"ADDI SP, SP, #64 // restore previous space on stack"
],
"description": "use this to save 8 registers in the Stack, including the return address of the procedure (where the procedure was called)"
},
"incremental for loop": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few suggestions for the loop.

  • ifl isn't immediately understandable so being a bit more explicit makes it easier to grasp and remember.
  • The use of a temporary register is annoying when writing legv8 code as it requires use of another register. Using flags, this can be simplified.
  • Also not using the term arr_len and using a generic upper limit makes it clearer that this can be used for any need, not just arrays.
  • I've also modified the description to include the equivalent C code.
  "increasing for loop": {
    "prefix": "for_increasing",
    "body": [
      "${1:loop name}_loop:",
      "// if counter ($2) greater than or equal to limit ($3), then exit",
      "SUBS XZR, ${2:counter}, ${3:upper_limit}",
      "B.GE ${1}_loop_done",
      "// loop body",
      "",
      "// increment counter ($2) by $4",
      "ADDI $2, $2, #${4:increment_amount}",
      "B $1_loop",
      "$1_loop_done:"
    ],
    "description": "Creates a for loop from counter to upper_limit. for (; counter < upper_limit; counter += increment_amount); Note: the counter and array size must be initialized before the loop."
  },

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, It`s Implemented

"prefix": "ifl",
"body": [
"${1:loop name}:",
"//comparing pointer to array length; if equal then exit",
"SUB ${2:temp}, ${3:counter}, ${4:arr_len}",
"CBZ $2, ${5:exit loop} ",
"//loop body",
" ",
"// increment pointer",
"ADDI $3, $3, #${6:Imt}",
"B $1",
"${5}:"
],
"description": "creates an incremental for loop. Obs: the register for the loop counter along with the length of the array are not created with the snippet, so they must be set"
},
"decremental for loop": {
"prefix": "dfl",
"body": [
"${1:loop name}:",
"//comparing pointer to 0; if equal then exit",
"CBZ ${2:counter}, ${3:exit loop} ",
"//loop body",
" ",
"// decrement pointer",
"SUBI $2, $2, #${4:Imt}",
"B $1",
"${3}:"
],
"description": "creates an incremental for loop. Obs: the register for the loop counter is not created with the snippet, so they must be set"
},
"return statement": {
"prefix": "rtn",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not say the full return?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it`s just that i have a tendency to abbreviate things, but I changed to "return"

"body": ["BR LR"],
"description": ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return from this procedure to the calling procedure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the description you mean? I was thinking of putting a bit more compact phrase like "return to the caller". What do you think?

}
}