F28HS Hardware-Software Interface Lecture 11: ARM Assembly Language 5.

Slides:



Advertisements
Similar presentations
ARM versions ARM architecture has been extended over several versions.
Advertisements

Passing by-value vs. by-reference in ARM by value C code equivalent assembly code int a;.section since a is not assigned an a:.skip initial.
1 ARM Movement Instructions u MOV Rd, ; updates N, Z, C Rd = u MVN Rd, ; Rd = 0xF..F EOR.
Chapter 10 And, Finally.... Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display A Final Collection of ISA-related.
1 System Calls (TRAPS) and Subroutines Patt and Patel Ch. 9.
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
Introduction to Embedded Systems Intel Xscale® Assembly Language and C Lecture #3.
The University of Adelaide, School of Computer Science
Assembly Language Working with the CPU.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
F28PL1 Programming Languages Lecture 5: Assembly Language 4.
Execution of an instruction
TK 2633 Microprocessor & Interfacing Lecture 3: Introduction to 8085 Assembly Language Programming (2) 1 Prepared By: Associate Prof. Dr Masri Ayob.
Chapter 6 Programming in Machine Language The LC-3 Simulator
Room: E-3-31 Phone: Dr Masri Ayob TK 2633 Microprocessor & Interfacing Lecture 1: Introduction to 8085 Assembly Language.
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Lecture 7: MIPS Instruction Set Today’s topic –Procedure call/return –Large constants Reminders –Homework #2 posted, due 9/17/
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
Micro-Computer Applications: Procedures & Interrupts Dr. Eng. Amr T. Abdel-Hamid ELECT 707 Fall 2011.
Lecture 4: Advanced Instructions, Control, and Branching cont. EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
CSC Computer Organization Lecture 4: Machine Instructions and Programs Terrence Mak.
ICS312 Set 9 Logic & Shift Instructions. Logic & Shift Instructions Logic and Shift Instructions can be used to change the bit values in an operand. The.
Topic 9: Procedures CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and Engineering University.
Lecture 8: Control, Procedures, and the Stack CS 2011 Fall 2014, Dr. Rozier.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
F28PL1 Programming Languages Lecture 4: Assembly Language 3.
1 Chapter 4 ARM Assembly Language Smruti Ranjan Sarangi Computer Organisation and Architecture PowerPoint Slides PROPRIETARY MATERIAL. © 2014 The McGraw-Hill.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
F28HS2 Hardware-Software Interfaces Lecture 7: ARM Assembly Language 1.
Arrays and Strings in Assembly
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
ARM-7 Assembly: Example Programs 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Lecture 6: Branching CS 2011 Fall 2014, Dr. Rozier.
F28HS2 Hardware-Software Interface Lecture 12: Assembly Language 6 & Summary.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Chapter 6 Digital Design and Computer Architecture: ARM® Edition
Format of Assembly language
Microprocessor and Assembly Language
Assembly Language Programming of 8085
Introduction to the ARM Instruction Set
The University of Adelaide, School of Computer Science
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Assembly Language Assembly Language
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
Processor Instructions set. Learning Objectives
Chapter 4 Addressing modes
BIC 10503: COMPUTER ARCHITECTURE
ARM Assembly Programming
Passing by-value vs. by-reference in ARM
Chapter 8 Central Processing Unit
The University of Adelaide, School of Computer Science
Topic 6: Bitwise Instructions
Chapter 9 TRAP Routines and Subroutines
Symbolic Instruction and Addressing
Optimizing ARM Assembly
Branching instructions
Overheads for Computers as Components 2nd ed.
Chapter 6 Programming the basic computer
Computer Architecture
Some Assembly (Part 2) set.html.
Multiply Instructions
Branch & Call Chapter 4 Sepehr Naimi
Introduction to Assembly Chapter 2
Computer Architecture and System Programming Laboratory
An Introduction to the ARM CORTEX M0+ Instructions
Presentation transcript:

F28HS Hardware-Software Interface Lecture 11: ARM Assembly Language 5

Software interrupt SWI operand – operand is interrupt number halts program saves PC branches to interrupt service code corresponding to operand

Software interrupt Linux/Posix provides an API to core system functions – file system, process control etc based on table of addresses of functions access via software interrupt R7 == system function id R0 - R6 == arguments after interrupt, hardware calls function in position R7 of table result returned in R0 really fast mechanism!

File read read – R7 == 3 – R0 == file descriptor - keyboard == 0 – R1 == address for byte sequence – R2 == number of bytes to read – returns a count of chars read in R0 or 0 at EOF

File write write – R7 == 4 – R0 == file descriptor - monitor == 1 – R1 == address of byte sequence – R2 == number of bytes to write

Example - copy keyboard to screen.global _start _start: loop: MOV R0, #0 LDR R1, =char MOV R2, #1 BL read MOV R0, #1 LDR R1, =char MOV R2, #1 BL write B loop read: MOV R7, #3 SWI 0 BX LR write: MOV R7, #4 SWI 0 BX LR ….data char:.word 0x00

Example - print decimal build table of powers of 10 for each power of 10 from 10^N to 0 – divide value by power of 10 subtract & count – add ‘0’ to count – print count as character 2^32 == == 10 digits need 1 st 10 powers of 10

Example - make 10^N table R0 == next 10^N addr R1 == count R2 == next 10^N R3 == 10 tens:.rept 10.word 0x00.endr... make10s:LDR R0, =tens MOV R1, #10 MOV R2, #1 MOV R3, #10...

Example - make 10^N table... pow10: STR R2, store next 10^N SUB R1, decrement count CMP R1, finished? BEQ done10 ADD R0, increment 10^N addr MUL R2, make next 10^N B pow10 done10: BX LR

Example - print decimal R0 == value R1 == count of 10^N R2 == address of next 10^N R3 == next 10^N R4 == division count printd: MOV R1, #10 LDR R2, =tens ADD R2, #36...

Example - print decimal... nextchar: LDR R3, get next 10^N MOV R4, division count = 0 loop10: CMP finished division? BLT showd SUB R0, take away 10^N ADD R4, increment count B loop10...

Example - print decimal showd: ADD R4, count -> char LDR R5, store char STR R4, [R5] PUSH save R0-R2 PUSH {R1} PUSH {R2} MOV R0, #1 LDR R1, =char MOV R2, #1 PUSH save LR BL write

Example - print decimal... POP restore LR POP restore R0-R2 POP {R1} POP {R0} next10: SUB R1, decrement 10^N count CMP R1, finished? BEQ endp SUB R2, decrement 10^N addr B nextchar endp: BX LR

Logical Shift LSL Rd, operand == Rd = Rd << operand add operand 0s to right like multiplying by 2 operand LSR Rd, operand == Rd = Rd >> operand add operand 0s to left like dividing by 2 operand

Logical operations AND Rd, Rn, operand 2 == Rd = Rn & operand2 ORR Rd, Rn, operand 2 == Rd = Rn | operand2 EOR Rd, Rn, operand 2 == Rd = Rn ^ operand2

Strings in the.data section:.ascii “ letters ” – bytes containing letters – 4 to a word – not 0 terminated.asciz “ letters ” – 0 terminated NB 4 bytes to a 32 bit word in “reverse order”

Strings e.g. digits:.asciz “ ” 0x330x320x310x30 0x37 0x360x350x34???0x00 0x380x39 word 0word 1 word 2 ‘3’ ‘2’ ‘1’ ‘0’ ‘7’ ‘6’ ‘5’ ‘4’ 0 ‘9’‘8’

String length count = 0 get 1 st word’s address repeat – get word from address – bytes = 4 – while bytes!=0 do AND 1 st word with 0xFF to get next byte if next byte==0 then done count = count + 1 shift word 8 bits right bytes = bytes-1 – move to next word address

String length R1 == address of next word R2 == count R3 == contents of next word R4 == next byte R5 == byte count.equ MASK, 0x000000ff.equ EOS, 0... LDR R1, =digits BL length... length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl

String length ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR R1 == address of next word R2 == count R3 == contents of next word R4 == next byte R5 == byte count

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 0 R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 0 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 0 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 4 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 0 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 0 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x30 4 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 1 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x30 4 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 1 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x30 3 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 1 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x30 3 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 1 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 1 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x31 3 R4 R5 0x000100e8 R1

String length and so on...

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 4 0x33 R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x33 0 R4 R5 0x000100e8 R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 4 0x33 R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x33 0 R4 R5 0x000100ec R1

String length length: MOV R2,#0 nextw: LDR R3,[R1] MOV R5, #4 nextb: MOV R4, R3 AND R4, #MASK CMP R4, #EOS BEQ endl ADD R2, #1 SUB R5, #1 CMP R5, #0 BEQ incr LSR R3, #8 B nextb incr: ADD R1,#4 B nextw endl: BX LR 4 0x R2 R3 0x x000100e8 0x x?? x000100ec 0x000100f0 0x33 0 R4 R5 0x000100ec R1

Command line arguments passed on stack *SP == argc *(SP+4) == address of argv[0] == name of executable *(SP+8) == address of argv[1] == 1 st argument *(SP+12) == address of argv[2] == 2 nd argument etc

Address offset notation can specify offset from register in address operand e.g. in LDR, STR etc LDR R i,[ R j,# int ] == ADD R j,# int LDR R i,[ R j ]

Example - show argv[1]. global _start _start: LDR R1, [SP,#8] LDR R2, =argv1 STR R1, [R2] BL length MOV R0, #1 LDR R3, =argv1 LDR R1, [R3] BL write BL _exit … argv1:.word 0x00 0x7efff7e0 SP 02 0x7efff7e0 0x7efff8fd 0x7efff7e4 0x7efff92c 0x7efff7e8 0x6c6c6568 0x78742e6f 0x… x7efff92c 0x7efff7f0 0x7efff7f4 ‘l’ ‘l’ ‘e’ ‘h’ ‘x’ ‘t’ ‘.’ ‘o’ … 0 ‘t’ argc argv[0] argv[1] $./argv hello.txt

Octal POSIX uses octal for system call flags base 8 0 dddd… decimalhexoctaldecimalhexoctal A B C D E F17

File open open – R7 == 5 – R0 == address of path string – R1 == flags - see fcntl.h read only: O_RDONLY == 0000 write only: O_WRONLY == 0001 create new write file: O_CREAT == 0100 – OR with O_WRONLY

File open open – R2 == mode only required for O_CREAT specifies access permissions returns R0 - file descriptor

File access permissions ~]$ ls -l total rwxr-x--- 1 greg staff Mar address.doc -rwxr-x--- 1 greg staff Sep addresses -rw-rw-rw- 1 greg staff 145 Aug AdobeFnt.lst -rw-r--r-- 1 greg staff Nov archive.pst... can control owner, group & world access 3 bits each: – r == read == 100 – w == write == 010 – x == executable == 001

File access permissions e.g. rwx r-x --- == == 0750 change access permissions in shell: $ chmod access file in ARM let’s use rw-r--r-- == == 0644

File close close – R7 == 6 – R0 == file descriptor

Example - file copy open input from argv[1] open output from argv[2] read from input while still input do – write to output – read from input close files

Example - file copy.data.equ O_RDONLY, 0000.equ O_WRONLY, 0001.equ O_CREAT, 0100 access:.word 0644 char:.word 0x00 fin:.word 0x00 fout:.word 0x00 ….global _start open input argv[1] LDR R0, [SP,#8] MOV R1, #O_RDONLY BL open LDR R1, =fin STR R0, [R1]

Example - file open output argv[2] LDR R0, [SP,#12] MOV R1, #O_WRONLY ORR R1, #O_CREAT LDR R3, =access LDR R2, [R3] BL open LDR R1, =fout STR R0, [R1] loop:LDR R1, =fin LDR R0, [R1] LDR R1, =char MOV R2, #1 BL read CMP R0, #0 BEQ endl LDR R1, =fout LDR R0, [R1] LDR R1, =char MOV R2, #1 BL write B loop

Example - file copy close files LDR R1, =fin LDR R0, [R1] BL close LDR R1, =fout LDR R0, [R1] BL close $./fcopy hello.txt hello2.txt $ ls -l hello2.txt -rw-r--r-- 1 greg staff 63 Jan 20 14:09 hello2.txt