Procházet zdrojové kódy

Add MVN and ADD example, also created b(uild) bash script

Foppe Hemminga před 6 roky
rodič
revize
dc7be9e4fa
8 změnil soubory, kde provedl 77 přidání a 0 odebrání
  1. 9 0
      b
  2. binární
      ch-02/MVNandADD
  3. binární
      ch-02/MVNandADD.o
  4. 17 0
      ch-02/MVNandADD.s
  5. 2 0
      ch-02/build
  6. binární
      ch-02/movexamps
  7. binární
      ch-02/movexamps.o
  8. 49 0
      ch-02/movexamps.s

+ 9 - 0
b

@@ -0,0 +1,9 @@
+#! /bin/bash
+
+if [ "$1" = "" ]; then
+    echo "Requires filename as argument"
+    exit 1
+fi
+filename="${1%.*}"  # Removes extension
+$(as -o "${filename}".o "${filename}".s)
+$(ld -o "${filename}" "${filename}".o) 

binární
ch-02/MVNandADD


binární
ch-02/MVNandADD.o


+ 17 - 0
ch-02/MVNandADD.s

@@ -0,0 +1,17 @@
+@
+@ Example of the ADD/ADC insttructions.
+@
+.global _start          @ Provide program starting address
+
+@ multiply 2 by -1 by using MVN and then adding 1
+
+_start:
+    MVN     R0, #2
+    ADD     R0, #1
+
+@ Set up the parameters to exit the program
+@ and then call Linux to do it.
+@ R0 is the return code and will be what
+@ we calculated above.
+    MOV     R7, #1      @ Service command code 1
+    SVC     0           @ Call Linux to terminate

+ 2 - 0
ch-02/build

@@ -0,0 +1,2 @@
+as -o  movexamps.o movexamps.s
+ld -o movexamps movexamps.o

binární
ch-02/movexamps


binární
ch-02/movexamps.o


+ 49 - 0
ch-02/movexamps.s

@@ -0,0 +1,49 @@
+@
+@ Examples of the MOV instruction.
+@
+.global _start      @Provide program starting address
+
+@ Load R2 with 0x4F5D6E3A first using MOV and MOVT
+_start:
+    MOV     R2, #0x6E3A
+    MOVT    R2, #0x4F5D
+
+@ Just move R2 into R1
+    MOV     R1, R2
+
+@ Now let's see all the shift versions of MOV
+    MOV     R1, R2, LSL #1      @ Logical shift left
+    MOV     R1, R2, LSR #1      @ Logical shift right
+    MOV     R1, R2, ASR #1      @ Arithmetic shift right
+    MOV     R1, R2, ROR #1      @ Rotate right
+    MOV     R1, R2, RRX         @ Rotate extended right
+
+@ Repeat the above shifts using
+@       the Assembler mnemonics
+    LSL     R1, R2, #1          @ Logical shift left
+    LSR     R1, R2, #1          @ Logical shift right
+    ASR     R1, R2, #1          @ Arithmetic shift right
+    ROR     R1, R2, #1          @ Rotate right
+    RRX     R1, R2              @ Rotate extended right
+
+@ Example that works with 8 bit immediate and shift
+    MOV     R1, #0xAB000000     @ Too big for #imm16
+
+@ Example that can't be represented and
+@       results in an error
+@ Uncomment the instruction if you want to
+@       see the error
+@   MOV     R1, #X0ABCDEF11     @ Too big for #imm16
+
+@ Example of MVN
+    MVN     R1, #45
+
+@ Example of a MOV that the Assembler will
+@       change to MVN
+    MOV     R1, #0xFFFFFFFE     @ (-2)
+
+@ Set the parameters to exit the program
+@ and then call Linux to do it.
+    MOV     R0, #0              @ Use 0 return code
+    MOV     R7, #1              @ Service command code 1
+    SVC     0                   @ Call Linux to terminate