Assembly Disassembled gcc output appears to do a "call 0" instead of "call function-offset", but works correctly

I had just a look at a very simple SPARC assembly output that I got from this C programm: int addition_func(int a, int b) { return(a+b); } void main() { int a = 20; int b = 19; int res; res = addition_func(a, b); } Disassembly of section .text: 00000000 <addition_func>: 0: 81 c3 e0 08 retl 4: 90 02 00 09 add %o0, %o1, %o0 00000008 <main>: 8: 90 10 20 14 mov 0x14, %o0 c: 92 10 20 13 mov 0x13, %o1 10: 82 13 c0 00 mov %o7, %g1 14: 40 00 00 00

How does an assembly instruction turn into voltage changes on the CPU?

I've been working in C and CPython for the past 3 - 5 years. Consider that my base of knowledge here. If I were to use an assembly instruction such as MOV AL, 61h to a processor that supported it, what exactly is inside the processor that interprets this code and dispatches it as voltage signals? How would such a simple instruction likely be carried out? Assembly even feels like a high level language when I try to think of the multitude of steps contained in MOV AL, 61h or even XOR EAX, EBX.

Assembly understanding CPU step by step journey of learning process

hello I want to learn how cpu works from scale of bit level to assembly level could somebody tell me ? which one would be better? top-down learning or bottom-up learning? and what am I suppose to do first? assembly language? or computer architecture? what sort of book, site, method would be good? I am interested in computer science/Artificial Intelligence but I have no compass to know how to get there efficiently your reply would be very thankful and helpful welcome your experienced story tha

Assembly What is on the stack before my program starts?

I am learning High Level Assembly Language at the moment, and am playing with the stack to better understand everything. I note that in the following program, I can pop the contents of the stack, without ever having pushed anything onto it 37 times before the program crashes. ike1: uns32 := 1; begin test1; while (ike1 < 38) do pop(eax); stdout.put(ike1, nl); stdout.put("ESP: ", esp, nl); stdout.put("EAX:", eax, nl, nl); add(1, ike1); endwhile; end test1; Each time the stack is popped i

Assembly Why do we substract 4 from arm926ejs_reset before loading it into sp?

I have a startup code for ARM926ej-s which supports ISA ARMv5TEJ. Startup code looks like below, but i switched some commands/data with comments for clarity. Lines which are still unclear to me are marked with a comment "@???????????????????????????????????????????????????????". I wonder, why do we need to substract "#4" from value (location of "arm926ejs_reset") stored in register "r3"? And then load it into a stack pointer 4 lines later, where we are setting the stacks for the first processor

Assembly Handle keyboard interrupts by polling interrupt request register (for x86)

I need to develop program for x86 that will handle keyboard interrupts by polling IRR. Program should work in real-mode under ms-dos. My main issue is that it don't work as I think it should work: appropriate IRR bit has non zero value even if no keys were pressed and value that was read from the port 0x60 is always 0x1c. Can someone explain me what I did wrong? Here is my polling loop: in al,21h ; read old IMR value or al,02h ; disable handling of interrupts from IR

Assembly How can I call a ptx function from CUDA C?

I am trying to find a way to call a ptx function (.func) from CUDA C. Say I had a ptx function like this: .func (.reg .s32 %res) inc_ptr ( .reg .s32 %ptr, .reg .s32 %inc ) { add.s32 %res, %ptr, %inc; ret; } I know I can call it from ptx like so: call (%d), inc_ptr, (%s, %d); But I have no idea how to call it from CUDA C. I know I can inline ptx assembly with asm(), but I haven't found a way to inline a function. Hope someone can help! Thanks!

Assembly Any tutorials for multiplatform assembler programming (Mac+Win+Nix)?

I want to learn assembler, but I really value multiplatform code, and most of the assembler languages and tutorials I've seen only cater to one specific assembler sub-language (either MASM or TASM or YASM) and one specific OS (either Mac or Windows or Linux). Are there assembler languages and tutorials that work on Mac OS X, Windows, and Linux? I suspect there's some X86 assembler format that GCC recognizes, and GCC is a multiplatform compiler--what would this language be called, and are there

Assembly xmm instructions - segmentation fault with memory source operand

I'm trying to add 4 numbers to other 4 numbers in assembly language with SSE2 instructions, using XMM registers. I did succeed, but I came over something I didn't understand. If I do the addition this way: movdqu xmm0, oword [var1] movdqu xmm1, oword [var2] paddd xmm0, xmm1 movdqu oword [var1], xmm0 It works perfectly fine. But if I try it this way: movdqu xmm0, oword [var1] paddd xmm0, oword [var2] movdqu oword [var1], xmm0 It gives me a segmentation fault. What is wrong with the seco

Assembly Can someone explain the following load and store instructions as part of the ARM ISA?

I'm just starting to learn ARM and I'm having trouble understanding what the load and store instructions do exactly. Load instructions: ldrsb ldrb ldrsh ldrh ldr Store instructions: strb strh str What does it mean to "load halfword" signed or unsigned? Or to "load byte" signed or unsigned? What is the difference between signed and unsigned, and in what particular applications would some of the load/store instructions be practical to use? All in all, I'm looking for an intuitive understa

Understanding c function in assembly

I am trying to learn how to understand c functions in assembler. I compiled the following c program using "gcc code.c -m32 -o code -S -fno-stack-protector" #include <stdio.h> void function( int a, int b, int c ) { char buffer1[5]; char buffer2[10]; } void main() { function( 1, 2, 3 ); } The assember output was the following: .section __TEXT,__text,regular,pure_instructions .globl _function .align 4, 0x90 _function: pushl %ebp movl %esp, %eb

Assembly boot loader working on virtual PC, not on real PC

My code works perfectly in virtualbox but not when booted on a real PC (from a USB pen drive which BIOS detects as a USB Hard Drive.) In virtualbox; the code reads sector 2&3 of the disk to memory, prints the first 128 bytes (as a debug step) then executes the code stored in those sectors. On my real PC, it successfully prints the correct bytes to screen (so obviously is reading the disk correctly, and writing it to the expected place in memory) but then stops execution at that point ra

Assembly Optimize zero checks in WinMIPS64

Consider the following code in WinMIPS64, that increases $s0, if $t0 is zero: bnez $t0, nonzero ;branch if $t0 is non-zero daddi $s0, $s0, 1 ;increment zero-count $s0 if zero nonzero: The problem with this code is that a branch delay is generated in the pipeline, until the outcome of the branch is known. $t0 can change elsewhere in the code and this snippet can be looped. Any ideas on how to make a more optimized zero counter? By the way, no hardware optimizations (forwarding, branch

Assembly Tasm program error

I need help with this assembly language program because this is my 1st time to try to write a program but I don't know how to start. Here's the question Write an assembly language program which allows the user to input a number of years (from 1 to 30) and then tells the user how many months, weeks, days, hours and minutes are there in that number of years. Example 1: Input: Number of years: 1 Output: Months: 12 Weeks: 52 Days: 365 Hours: 8760 Minutes: 525600 I got this from our laboratory man

Can somebody explain this delay routine written in assembly language?

I have this delay routine in assembly language, can anybody explain me how this works? I'm very much new to assembly and trying to understand the insights. Can anybody help me understand the functionality of PUSH & POP? Any help will be appreciated :) DELAY: MOV CX, 0FFH DLY5: PUSH CX MOV CX, 03FFH DLY10: NOP LOOP DLY10 POP CX LOOP DLY5 RET

Assembly Homework - TICTACTOE - addressing issue

2. .data # data segment for variables and strings # These are all the strings that will need to be outputted to the console title: .asciiz "Tic-Tac-Toe!\n\n" oprompt: .asciiz "O player: Please enter row/col, one per line:\n\n" xprompt: .asciiz "X player: Please enter row/col, one per line:\n\n" invposstr: .asciiz " is an invalid position. Try again.\n\n" owinstr: .asciiz "O won the game,\n\n exiting. . ." xwinstr: .asciiz "X won the game,\n\n exiting. . .

Assembly How to design a virtual cpu / instruction set: distinguish LDA $02 from LDA B

So, I'm designing my own virtual CPU. I have some registers and memory and can execute some rudimentary instructions. But, now I'm stuck. How can I differentiate (in my assembled "machine code") between: LDA $02 ; Load the hex value 0x01 into register A and LDA B ; Load the value of B into A Right now I have encoded the operand ($02 and B) both as a value of 0x02. The instruction LDA is encoded as a single Word (uint16 at this point). This will obviously give problems. What is the best

Assembly ARMv6 Best Practices for Register Use in Function

Total n00b at Assembly, but I feel like I'm getting the hang of it. However I have a question about best practices for using registers in a function. As I understand it: of the 13 available general purpose registers on the ARM11, by convention registers 0-3 are meant to be used for passing in arguments (with 0 & 1 also being used for return values) while 4-12 are meant to be used for storing working values for the duration of the function. However I've also seen code examples where people

Assembly Segfault when storing reg to var in section .DATA

So I am trying to write some code using x86 and I can't seem to get it to move contents of a register to a spot in memory. The code is just this global main SECTION .DATA var_i: DD 0 SECTION .TEXT main: push DWORD 4 pop EAX mov [var_i], EAX mov EAX, 0 ret I am using nasm and gcc on the code. The problem I am having is that whenever I try to move to the spot in memory it segfaults

Assembly MIPS outputting 0.0 instead of input

completely new to MIPS and Assembly. Trying to make a simple program that reads a float and outputs it. Having a bit of trouble: .data msg2: .asciiz "please enter a value: " .text .globl main main: li $v0, 4 #load value for print_string la $a0, msg2 #load address of msg2 into $a0 syscall #print msg2 to screen li $v0, 6 #load value for read_float mov.s $f1, $f0

assembly language count all 'a' in character input

my code supposed to count all character 'a' in every user input i use cmp if equal then my program jump to 'incre:' that increment the value of bl.the output is always this>¶< .i don't know where the problem is title sample.prog cstack segment para stack 'stack' dw 200h cstack ends cdata segment para 'data' msg1 db 'ENTER 9 CHARACTER: $',10,13 msg2 db 10,13,'NUMBER OF a: $' cdata ends ccode segment para 'code' assume cs:ccode,ds:cdata,ss:cstack main: mov ax,cdata mov ds,ax mov ah,09h

Assembly this code to find the largest element in an array in nasm does not work

section .bss digit0: resb 2 digit1: resb 1 answer1 : resb 1 answer2 : resb 1 answer : resw 1 array: resb 50 element: resb 1 num: resb 1 temp: resb 1 largest: resb 1 smallest: resb 1 count: resb 1 section .data msg1: db "Enter the number of elements : " size1: equ $-msg1 newline: db 0Ah msg2 : db "enter a number:" size2 : equ $-msg2 len2: equ $ - newline section .text global _start _start: mov byte[count], 0 ;Printing the message to enter the number mov eax, 4 mov ebx, 1 mov e

Overflow bit in assembly

I'm attempting to add 2 numbers in assembly. However, the resulting number may be larger than the 16 bit memory slot. I set the overflow bit to notify me of when there is overflow but how do I deal with the overflow? I know it varies between devices, but in general how would I go about saving the "overflowed" values? Could I save it into another memory slot? I'm using the TI C5515 DSP board if that helps. I'm rather new at writing assembly so perhaps this is an obvious question. I'd appreci

Assembly Binary Bomb phase 3 stuck

I am honestly very confused on this due to my bomb phase 3 not looking like any of my classmates or the example given to me by my professor. Any help would be greatly appreciated. I have a copy of my recent terminal for use and ill put the I have been trying my hand at this for the better part of 5 hours, I've gotten far enough to know that %d %d is the layout requested, and that its asking for 2 numbers with i believe one of them being negative. Due to the comparison statement and jg here 0

Assembly Generate .abs file from .asm file

I have a Micropross SC2 device as simulator.From the document we found that we can load library(Motorola formatted .abs file) on flash memory of the device. My problem is that I have never heard about .abs file(My badluck).From this I got the idea "How can we generate the .abs file".(I think so) I have created a small program in assembly language(.asm file) and I am using MASM32.I have also build the file and I got .obj file and .exe file but

Assembly How to transpose a 16x16 matrix using SIMD instructions?

I'm currently writing some code targeting Intel's forthcoming AVX-512 SIMD instructions, which supports 512-bit operations. Now assuming there's a matrix represented by 16 SIMD registers, each holding 16 32-bit integers (corresponds to a row), how can I transpose the matrix with purely SIMD instructions? There're already solutions to transposing 4x4 or 8x8 matrices with SSE and AVX2 respectively. But I couldn't figure out how to extend it to 16x16 with AVX-512. Any ideas?

Having trouble conceptualizing two Assembly programs

the two following programs were questions on a test that I took a few weeks ago, but I didn't get full credit for. I can't really figure out how to do them in any other way. I don't have the original code for them, but I was wondering if you guys/girls could show me examples of how you would have done it so that I can better prepared for our next test. If you could explain how your program works it would be greatly appreciated as well. Thank you! 1.) Write the a program to output your name 10 t

Assembly How do I compare values of integers inside strings using MIPS?

I wrote this simple program just to try and check if slt or any other comparing instruction can tell me if the value inside the string and the integers it represent are bigger then the other one. It's not working and I don't know why. Is this comparison legal or should I turn the strings to real integers? Why doesn't it work? from my understanding the address of each string+offset should move the correct value too $t0 and $t1. How do I turn this strings to the integers they represent? what c

How to tell information about parameters from reading assembly code

I'm working on a binary bomb project for my university course. In doing the different "phases" of the bomb- I have to figure out the correct input in order to prevent the bomb from detonating. One part of the problem I am having trouble with is what do I look for within assembly code to determine information about the parameters. I would primarily like to know how many parameters the function takes in. My professor said there's an easy way and a hard way to figure this out but I am having trou

Intel intrinsics assembly code

I am considering simple problem - speeding up the calculation of component-wise product of two arrays of doubles. I have noticed that using AVX commands I get only around 20% speedup, comparing to sequential multiplication in a loop. I decided to check the latencies for the both cases and became confused with the assembly code of the load operation: ### __m256d pd; ### pd = _mm256_load_pd(a); movq -112(%rbp), %rax //Pushing the pointer to the stack

Assembly Tag OF in 32 bit register multiplication

I've a problem with product in Assembly. I want to multiplicate two matrixes with dimensions, ad exemplum, 1raw x 1column. If result is bigger than 2^15 IMUL sets the flag OF=1 beacuse of the overflaw, but i don't understand why, infact i'm using 32 bit register and not 16 bit. Here is some code to explain this problem, for example: short int mat1[] = {-70}; short int mat2[] = {20000}; __asm { lea eax, mat1 lea ebx, mat2 xor edx, edx xor ecx, ecx movsx

Assembly What does this LSB function do?

I have the following code which I think (but not 100% sure) computes the LSB of a given 64-bit integer. Unfortunately, I don't understand the implementation. What is bsfq? What is =r? static inline unsigned lsb(uint64_t b) { size_t idx; __asm__("bsfq %1, %0": "=r"(idx): "rm"(b)); return idx; }

How to receive parameters from MS-DOS and compares it in Assembly 16-bits?

Good night, what's the simpliest way to receive a simple char as parameter in Assembly 16-BITS, and compares to test if is the right one? I'm for 2 days searching for examples of how to do it, but no one had worked for me... I tried that code from StackOverflow and it doesn't work, the dx has 81h no the hex of the char that I need. I'm very newbie in Assembly, so I need little examples of code to understand... I want the simpliest way possible, I don't want to waste your time... Thanks. In MS-DO

Assembly Why does CUDA PTX have clz but no ctz, and CUDA headers have "fake ffs" but no fls?

PTX is an intermediary representation for compiling C/C++ GPU code into, eventually, individual micro-architecture's SASS assembly language. Thus it is not supposed to be encumbered by specific holes/gaffs/flukes/idiosyncrasies in the actual instruction sets of specific nVIDIA GPU micro-architectures. Now, PTX has an instruction for counting the number leading zeros in a register: clz. Yet - it lacks a corresponding ctz instruction, which counts the number trailing zeros. These operations are '

Assembly undefined reference to address even though there's no reference to it on the line mentioned

I'm getting the following error: build/main.o:source/main.s:91: undefined reference to `addr_r' collect2: error: ld returned 1 exit status from this code: 82] @ Register Aliases for subroutines 83] addr_r .req r4 84] 85] write_latch: 86] mov fp, sp @ save position in calling code 87] PUSH {r4-r10} @ preserve variable registers 89] @ do stuff here later 90] POP {r4-r10} @ restore variable registers 91] bx lr

Assembly x86 check if 3 values can form a triangle

I have to do this problem where I have the sides and I have to check if they can form a triangle. Now I have this code but I don't know why I get both of the messages.I am new to the assembly language. .model small .stack 128 .data a dw 1 b dw 20 c dw 3 msg1 db 'The sides can form a triangle$' msg2 db 'The sides cannot form a triangle$' .code mov AX, @data mov DS, AX MOV AX,a add AX,b mov bX,b add bX,c mov cX,a add cX,c CMP AX,c JAE

Assembly Can I increment an SRAM address?

I have to write a program that can store consecutive integers starting with 11 up to 40 in SRAM starting from address 0x0200. This is what I tried to do in Assembly language: LDI R16, 10 LDI R17, 30 .EQU MEM = 0x0200 L1: INC R16 STS MEM, R16 INC MEM DEC R17 BRNE L1 L2: jmp L2 However, Atmel Studio doesn't allow me to increment the address. Is there any solution to this problem without having to type 30 STS's?

Assembly How can early BIOS use CALL? (follow-up)

This is a follow-up to How can early BIOS use CALL?, same ROM file, same setting. Thanks to Brendan I know that upon a cold boot the jump discussed there would be taken and a call instruction would be skipped at that moment. But there are other memory writes soon after that. This is a shortened listing, the full thing with all complete branches (55 lines) can be found at [Beginning is the same as in the first question] f000:e045 out 0x70, al ; CMOS controller:

Assembly language prints character twice with function call but not when executed directly

I am trying to make my own bootloader written in 16 bit assembly. I am able to print text to a screen using int 10h, AH = 0Eh. If I run MOV AL, 65 MOV AH, 0Eh int 10h HLT I am successfully able to print A to the screen. However, if I am to do MOV AL, 65 CALL printc HLT printc: MOV AH, 0Eh int 10h RET I end up getting AA displayed on the screen instead. Why is this and how would I fix it? Here is my full code: BITS 16 ORG 0x7C00 MOV DS, AX MOV SI, 0x7C00 MOV AL, 65 CALL

How do I display an integer in video mode 13h in x86 Assembly?

I'm currently working on a project for school in x86 assembly. We are coding the retro game Breakout. We render the game in video mode 13h. The problem is that we would like to display the current score of the player on the screen. This is a procedure we have for printing a $-terminated string to the screen: PROC displayString ARG @@row:DWORD, @@column:DWORD, @@offset:DWORD USES EAX, EBX, EDX MOV EDX, [@@row] ; row in EDX MOV EBX, [@@column] ; column in EBX MOV AH, 02H ; se

What is the proper SWI statement to print integers in assembly?

Im trying to make a while loop in assembly but my SWI statement to get the numbers to "print" is giving me an error. .text mov r1, #10 mov r2, #1 b L2 L3: SWI 0x6b sub r1,r1,#-1 L2: cmp r1, r2 bgt L3 The error occurs once i get to the SWI 0x6b and the exact error message is "Unimplemented SWI code.

Assembly Error: Range error (130 not in [-128..127]) message when I try to assemble my nes game

I get this error at line 248 that doesn't make any sense: Error: Range error (130 not in [-128..127]) I have no idea why this is happening because all there is at that line is just a jump command to a label, which is not even that far away from the jump if that's what a range error means. This seems completely random. Could you help? Here is the code: collisonram = $700 .segment "HEADER" .byte "NES" .byte $1A .byte $02 .byte $01 .byte %00000000 .byte $00 .byte $00 .byte $00 .byte $00 .by

Is there any way to detect invalid characters when using ReadHex function in assembly(masm32)?

I wanted to create a program that receives new value if the input value(32-bit hexadecimal) is not correct. Using a ReadHex function was very useful for this, but I have no idea about how to detect invalid characters. I tried entering invalid characters on purpose to see what that does on EAX register, but it just considers invalid characters as 0. ex) 4FZC becomes 4F0C

Assembly MASM: how to resolve error "immediate operand not allowed"

My assembly program has following structure: BPB_FAT16 STRUCT ; Base BPB_FAT16. Size=0x19=25. BytesPerSector DW 0x0200 ; Size of HW sector, usualy 512. SectorsPerCluster DB 0x01 ; Valid values 1,2,4,8,16,32,64,128. ReservedSectors DW 0x0001 ; NrOfSectors preceding FAT. NumberOfFats DB 0x02 ; RootEntries DW 0x00E0 ; Max number of YWORD entries in the ;root dir. SmallSectors DW 0x0B40 ; See also .Large

Assembly Different types of object files

The e_type in the ELF document lists the following available object file types: Name Value Meaning ET_NONE 0 No file type ET_REL 1 Relocatable file ET_EXEC 2 Executable file ET_DYN 3 Shared object file ET_CORE 4 Core file ET_LOPROC 0xff00 Processor-specific ET_HIPROC 0xffff Processor-specific Where can I learn more about what each of these file types are? For example, I've never heard of a "Processor-specific"

Unusual behavior of ARM assembly program

I have been writing JIT ARM compiler for simple expressions. My Just-in-time compiler is given addresses to the functions and variables that will be used in the expression and the expression itself. And it generates ARM code that computes the expression. This is the output of my compiler for the expression inc(1) + 1: start: push {r4} //saving r4 ldr r0, [pc] //writing the constant into r0 b skip0 //skipping data line .word 0x1 skip0: push

Assembly Sum of Matrix Specific Row

I have this code, I can print the sum of a specific column but how do i print the sum of a specific row? This program calculates the sum of the elements of a column of an M x N matrix. Constants .eqv NUM_ROWS 5 .eqv NUM_COLS 6 .eqv ELT_SIZE 4 .eqv PRINT_INT 1 .eqv PRINT_STR 4 .eqv READ_INT 5 .eqv TERMINATE 10 .data Input_str: .asciiz "Enter the column number, 0-based: " Summary_str: .asciiz "Sum of elements in the specified column: " Matrix: row0:

  1    2   3   4   5   6  ... 下一页 最后一页 共 88 页