assembly

segmentation fault at every assembly code

社会主义新天地 提交于 2021-02-17 07:10:03
问题 I'am trying to learn assemly on raspberry pi.But I couldn't get started, every code i write gets "Segmentation Fault". .text .global _start _start: MOV R0, #2 SWI 0 This code gets segmentation fault. Even if I delete the MOV line it gets segmentation fault. 回答1: Try: bx lr @ Exit if use gcc as linker or mov r7, #1 @ Exit if use ld as linker svc #0 @ Exit if use ld as linker Some version use swi , I have success with svc using ld as the linker. If you use gcc as the linker, the lr register has

segmentation fault at every assembly code

梦想与她 提交于 2021-02-17 07:09:05
问题 I'am trying to learn assemly on raspberry pi.But I couldn't get started, every code i write gets "Segmentation Fault". .text .global _start _start: MOV R0, #2 SWI 0 This code gets segmentation fault. Even if I delete the MOV line it gets segmentation fault. 回答1: Try: bx lr @ Exit if use gcc as linker or mov r7, #1 @ Exit if use ld as linker svc #0 @ Exit if use ld as linker Some version use swi , I have success with svc using ld as the linker. If you use gcc as the linker, the lr register has

Why does the Linux Open system call not need a buffer size parameter for the path?

柔情痞子 提交于 2021-02-17 06:25:26
问题 Why does the open system call not need a buffer size parameter like the write system call does? How do these two system calls treat their string parameters differently? Does the open system call assume a zero-terminated string for the path parameter while the write system call does not? If so why the inconsistency? Why not make all (or none) of the system calls that use strings / arrays require a size parameter? 回答1: UNIX was developed as an operating system for programs written in assembly,

Moving a character back and forth across the monitor

末鹿安然 提交于 2021-02-17 06:04:42
问题 Write a program that will move a character from left to right and then back again across the monitor of the PC a number of times as specified by the user's input. The user is to be prompted for the character to display and how many times to move it back and forth. An input of '?' and 1 would cause the '?' to move back and forth across the monitor 1 trip. Your program must only allow entry of numbers from 1 to 4 inclusive. Use a loop that allows an exit only if the value is greater than zero

Implementing a flow “(1) if {…} else if {…} … (2)” in Assembly

五迷三道 提交于 2021-02-17 05:57:57
问题 I have the following flow in C: // some stuff1 //................ if (something1) { func1(); func2(); } else if (something2) { func3(); func4(); } // some stuff2 I wonder, how can I encode that in Assembly? I mean, not exact intructions, but the flow. Should I use labels for jumping to what's inside if (something1) { ...} and "else if (something2)"? How would I return then to "// some stuff2"? ; some stuff1 ; and then cmp [some_struc], SOME_CONST je .... ???? cmp [some_struc], SOME_CONST2 je

Check if a number is even

我只是一个虾纸丫 提交于 2021-02-17 05:56:19
问题 I'm working my way through low level bit hacks, and would like to write an assembly program for each. Here is what I have for checking if a number is even or not: is_even: # check if an integer is even. # This is the same as seeing if its a multiple of two, i.e., & 1<<n - 1 # rdi stores the number xor %eax, %eax test $0b1, %rdi setz %al ret _start: mov $5, %rdi call is_even Are there any ways to improve the above or make it more readable? Is it possible to do the is_even check with 2

Newton - Raphson inversion algorithm in assembly

纵饮孤独 提交于 2021-02-17 05:44:29
问题 I am trying to implement Newton - Raphson inversion algotihm in assembly according to this equation: Xn+1 = Xn(2-b*Xn) My function is: .data const: .int 2 .text .global inversion inversion: pushl %ebp movl %esp, %ebp fldl 8(%ebp) # load b fldl 12(%ebp) # load X0 inv: fst %st(2) # save Xn fmul %st(1), %st(0) # b*Xn fsubr const # 2-b*Xn fmul %st(2), %st(0) # Xn(2-b*Xn) fcomi %st(2), %st(0) # check if it the same result as before jne inv # jump # it should return the st(0) leave ret And my C

Determine the length of a string in MIPS32

孤街浪徒 提交于 2021-02-17 05:43:05
问题 I'm trying to determine the length of an input string using buffer and memory allocation. So lets say I allocate some memory and read a string and store it into the buffer. Then how can I figure out how long the string is? 回答1: Count from the beginning until you find a null character (0). Something like: la $t0 string loop: lb $t1 0($t0) beq $t1 $zero end addi $t0 $t0 1 j loop end: la $t1 string sub $t3 $t0 $t1 #$t3 now contains the length of the string 来源: https://stackoverflow.com/questions

Inline assembly statements in C code and extended ASM for ARM Cortex architectures

你。 提交于 2021-02-17 05:18:30
问题 I am trying to compile the following two pieces of code with ARM Compiler 5 for a Cortex A microprocessor: Part 1 : static inline void cp15_write_sctlr(uint32_t value) { asm("mcr p15, 0, %0, c1, c0, 0" :: "r"(value)); } static inline uint32_t cp15_read_actlr(void) { uint32_t actlr; asm("mrc p15, 0, %0, c1, c0, 1" : "=r"(actlr)); return actlr; } Part 2 : static inline void dmb(void) { asm("dmb" ::: "memory"); } static inline void dsb(void) { asm("dsb" ::: "memory"); } static inline void isb

MIPS - Array in array index

好久不见. 提交于 2021-02-17 05:17:25
问题 What is the following C code in MIPS? f = A[B[i]] I'm told it can be done in 6 lines but can't quite figure out how. f is in $t0 , i is in $t3 , A[] is in $s0 , and B[] is in $s1 . All types are integer. The best I am able to think of is lw $t5, $t3($s0); # Doesn't work because lw syntax doesn't accept a register as an offset lw $t6, $t5($s1); sadd $t0, $t6, $zero Obviously this is wrong. How would i go about getting the correct offset for each line? Thanks. 回答1: There might be more efficient