spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » ASSEMBLY » Page 1
copy certain characters from one string to another in assembly
After mov cl, [bx+1] check, whether cx is zero. If cx is zero, you have to break the loop at this point, because otherwise, the loop would be repeted 65536 times. Insert this code in the line after mov cl, [bx+1]: cmp cx, 0 je exit and insert a label exit (or whatever you want to insert) at the end. This makes sure, that the code is not executed if cx is zero.

Categories : Assembly

How to initialize variables, compile and run GNU assembly program
Initialising variables You can initialise variables in your .data section. You usually do it like this: label: .directive values... For example, listofnumbers: .byte 1, 2, 3, 4, 5, 6 There is a list of "pseudo-ops" which includes the data definition directives like .ascii, .byte, and so on. You refer to the address of listofnumbers in your code using $listofnumbers and the value at the addre

Categories : Assembly

[MASM]Another 'cannot use 16-bit register with a 32-bit address' error
I've done some researches and here is what I've learned .MODEL directive enables use of simplified segments controls the name of the code segment controls the default distance for procedures. the syntax is :.MODEL memorymodel, options-optional and memorymodel can be TINY, SMALL, COMPACT, MEDIUM, LARGE, HUGE,or FLAT Flat model is similar to tiny model in tha

Categories : Assembly

Add 32-bit floats in eax/ecx registers?
No, you can't do that. As far as generating code goes, you can simulate fld r32 easily enough through the following sequence for example (optimized for size ;)) : push r32 fld [esp] pop r32 Consider using SSE if available, which does offer direct GPR-to-XMM moves using the movd instruction. Adding the two registers could then look something like: movd xmm0, eax movd xmm1, ecx addss xmm0, xmm1

Categories : Assembly

Using scanf with x86 GAS assembly
As you feared, movq %rcx, %rsi is not correct. You need to pass a pointer to memory. Registers are not part of the memory address space and thus you can't have pointers to them. You need to allocate storage either globally or locally. Incidentally, you should not put your data (especially writable) into the default .text section, as that is intended for code and is typically read-only. Also, calli

Categories : Assembly

Push and Pop in arm
The mentioned stack operations are only shortcuts for memory operations using sp in the address part. E.g. PUSH {r3} POP {r3} are aliases for str r3, [sp, #-4]! ldr r3, [sp], #4 First operation says "store content of r3 into [sp - #4] and decrement sp by 4". Last one "load r3 from [sp] and increment sp by 4". Instead of {r3} you can use any other register or register sets (e.g. {r1,r2,r3,l

Categories : Assembly

creating a linked list in assembly language 8086
Sure thing, for example mov di, [di] mov di, [di] Advances a couple of places through a linked list where the next link is the first thing in the node (if it isn't, add a constant offset). A larger problem here is allocating and deallocating those nodes.

Categories : Assembly

Assembler Print the number on the screen
I assume that you want to get signed numbers and that you you know how negative numbers are coded (see Wikipedia's article of Ones' complement. MSDOS doesn't provide a ready function to convert data to numbers, so you have to create such a function by yourself. The main issue is to repeatedly divide by 10 and to process the remainder. There are a lot of examples and explanations on the net, search

Categories : Assembly

Is there translate-table XLAT instruction in ARM programming?
My understanding of XLAT is that it is a table lookup. This is standard to all ARM CPUs. It is called double register indirect and looks like, ldrb r0, [r1, r2] ; get memory location r1+r2 and place in r0. The form with scaling is useful for accessing 'half-word', 'word', 'double-word' and other power of 2 data structures. There is also a thumb2 instructions TBB and TBH, but this is a slig

Categories : Assembly

Multiplying word size inputs x86
It seems like you have a bug in your first example. The result of the mul bl instruction will be a word-sized result in the AX register. But then you add the value at memory address num1 to the AL register. That's going to mess up your result if the addition results in a carry (i.e. makes AL roll past 255). Consider, for example, if the [num2] contains 30. The result of the mul bl instruction, the

Categories : Assembly

What does bx lr do in ARM assembly language?
bx stands for branch and exchange instruction set Which means that according to the lsb (least significant bit) of the address to branch to, the processor will treat the next instruction as ARM or as thumb. As lr usually holds the return address, it means that this is a return from a function, and if the lsb of lr is 1, it will treat the code at that address as thumb, otherwise, it will treat it

Categories : Assembly

AVR Assembler Labels
Labels appear in assembly code, but the assembly code must be turned into machine instructions to be run on the device. What this quote is saying is that as the assembly file is processed, the label in jmp instructions is replaced with the address of the instruction following the label. The address itself is discovered during the compilation process as the instructions are collated. If you want

Categories : Assembly

Differences of x86 and x86-64 machine code
There's actually no difference between the old 32bit push and the new 64bit push, that's one of the few instructions that are implicitly 64bit. Relative branches and calls still use 32bit offsets. Some actual differences are: the REX prefix, obviously, for extra registers (also remember sil and dil - a REX prefix with none of the bits set can still matter!) the REX prefix again, it used to be

Categories : Assembly

What's wrong with x86 ENTER instruction?
The nested form of the enter instruction assumes you already have a valid frame pointer in ebp, which is not the case on linux at the start of the process. Presumably that is why you get a fault. Try this instead: _start: enter $0, $0 # set up initial stack frame push $1 push $2 # simulate two previous frame pointers enter $16, $3 # nested proc level 3, e

Categories : Assembly

Atmega328p ADC assembly doesn't convert
I think sts EIFR, R16 should actually be out EIFR, R16. Then, you're configuring PORTD.2 (INT0) as an output, which causes it to become 0 and stay there. No edge, no INT0, no ADC trigger. If you have an external pull-up use ldi R16, 0x00 out DDRD, R16 out PIND, R16 To use the internal pull-up use ldi R16, 0x00 out DDRD, R16 ldi R16, (1<<2) out PIND, R16

Categories : Assembly

TASM extra characters when calling subroutine
call only takes a single operand, the address of the subroutine. You need to pass arguments by hand, according to whatever convention tasm uses if you declare a proc like you did. Assuming it uses the usual stack based convention, you will need something like: push offset msg_description call print_msg add sp, 2 ; remove argument if called proc doesn't end with `ret 2`

Categories : Assembly

Assembly 80286: Accessing n-th byte of variable
You forgot to initialise DS. Change mov ax,data mov es,ax to mov ax,data mov ds,ax mov es,ax Is the initialisation of ES really needed?

Categories : Assembly

What is the difference between section and label in assembly in NASM?
Well, there's a nice Manual, you know. http://www.nasm.us if you haven't got it. It matters which output format you're using - the -f switch. In general... section and segment are aliases, they do the same thing. They are not case sensitive, you can use SEGMENT if you want to. Most output formats (not -f obj) have "known names" - .text, .data, .bss (and a few more). These are case sensitive - sec

Categories : Assembly

jb in Assembly and value in register
Operations on eax do not directly affect the value of edx but since it has been initialized to 1 and the zeroing depends on the outcome of an operation on eax, it is affected indirectly. jb is an unsigned operation, and does what you said. Note that 7FFFh is below 8000h so the jump will be taken, thereby skipping the mov edx, 0. Thus, the final value in edx will be 1. You can run this code and s

Categories : Assembly

x86 linux system call calling convention?
That is how you pass the arguments. The calling convention for system calls says which registers hold the arguments. The kernel expects them there, and you should put them there. See also this reference. While the usual 32 bit cdecl convention uses the stack to pass arguments, there are similar conventions in user mode (notably fastcall) that also use registers to pass arguments. The standard con

Categories : Assembly

Mixing Assembly & Fortran plus parallelization (OpenMP)
Each thread has its own set of registers. That's obvious in the case when threads execute on separate cores, since each core contains a full set of registers. When multiple threads are time-sharing the same physical core, the state of the user-visible registers is saved when execution switches to a different thread and then restored later on when the execution switches back to the original thread

Categories : Assembly

How does xchg works with string for assembly x86?
I wrote a C-function to test this: #include <stdlib.h> void swapfun(char *restrict fp, char *restrict sp) { while (*fp) { char temp = *fp; *fp++ = *sp; *sp++ = temp; } return; } gcc 4.8 -O3 suggests the following (x86-64, but it's easily adaptable): swapfun: jmp .L10 .L7: movzbl (%rsi), %edx addq $1, %rdi addq $1, %rsi movb %dl

Categories : Assembly

Call C kernel from assembly bootloader
Here is what I successed to do but with a kernel written in asm : boot.asm : [org 0x7c00] KERNEL_OFFSET equ 0x1000 call load_kernel ;Switch PM cli lgdt [gdt_descriptor] mov eax, cr0 or eax, 0x1 mov cr0, eax jmp 0x8:init_pm [bits 32] init_pm : mov ax, 0x10 mov ds, ax mov ss, ax mov es, ax mov fs, ax mov gs, ax mov ebp, 0x90000 mov esp, ebp call KERNEL_OFFSET

Categories : Assembly

Create a File using ARM Assembly
The x86 code you reference relies on a BIOS being available to perform this task for you. Your ARM environment contains no BIOS, so without an operating system you are simply out of luck. See This Question for a little but more information about what your x86 example actually does. Another Question is a more descriptive one of the work you need to do to achieve what you ask, once you are within

Categories : Assembly

SSE instructions in ASM function
There are many problems. You seem to have forgotten that xmm registers are 16 bytes, instead pretending to process 7 bytes per iteration and starting at "1 before the end" (and then sticking out past the end by 15 bytes). Fortunately the aligned loads caught it, otherwise you would have gotten a completely broken output and one of the most annoying things to debug: occasional crashes, possibly in

Categories : Assembly

How to calculate parity of a 32bits number in assembly?
Many ways to do this, of course. If you decide to use the hardware parity flag, keep in mind that it only checks the low 8 bits. A solution using this approach might be to process your 32 bit input as four 8 bit values, and use XOR on the partial results: p(31:0) = p(31:24) ^ p(23:16) ^ p(15:8) ^ p(7:0) To get the 8 bit units, you can use SHR and to get the partial values you can XOR, use the SE

Categories : Assembly

Recursion function with pushing parameters not work correct
You expect edx and ecx to be preserved but they will of course be overwritten by the next recursion. You might want to try something like this instead: fun: mov edx, [esp+4] sub edx, 2 push edx call fun add esp, 4 mov edx, [esp+4] ; reload argument sub edx,1 push eax ; save current result push edx call fun add eax, [esp+4] ; add saved result add esp, 8 ; remove argument and saved result ret Of

Categories : Assembly

Assembly language procedure to take 2-digit input from the user
You don't need to worry, this code just reads hex,assumes capital Letters and does not check about any other chars typed. It first subtracts '0', so in case of a digit you will have a result le 9. If not, it assumes you typed 'A'..'F', (0x41..0x46),and therefore subtracts 7 to get the correct result 0x0a..0x0f

Categories : Assembly

Changes value use in all functions (NASM)
You are not passing any arguments to function, so presumably the comparison will always be false and eax remains unchanged. The first time around it should be zero, from then on it's the return value from printf which may very well be 8. You probably want to pass ebx as argument to function and either preserve eax through printf or zero it explicitly in function. For example: main: pushad mov eax

Categories : Assembly

How to keep negative numbers in assembly language TASM ? x86
Your code contains multiple errors: mov al, a cbw mov bl,9 ## This cbw will do a conversion AL -> AX ## cbw/cwd instructions always influence the AX ## register. It is not possible to use cbw for ## the BX register! ## ## BTW: The value of the BH part of the BX ## register is undefined here! cbw sub bx,ax mov res1, ax mov al, c cbw ## Mul is an unsigned multiplication! ## Imu

Categories : Assembly

Optimal SIMD algorithm to rotate or transpose an array
uint64_t A[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; __m256i row0 = _mm256_loadu_si256((__m256i*)&A[ 0]); //0 1 2 3 __m256i row1 = _mm256_loadu_si256((__m256i*)&A[ 4]); //4 5 6 7 __m256i row2 = _mm256_loadu_si256((__m256i*)&A[ 8]); //8 9 a b __m256i row3 = _mm256_loadu_si256((__m256i*)&A[12]); //c d e f I don't have hardware to test this on right now but something like the f

Categories : Assembly

How do I move a byte into a specific location in a data register?
I found a solution using LSL (Thank you, Chris Stratton), and SWAP: MOVE.B #$B1,D0 LSL #8,D0 MOVE.B #$B2,D0 SWAP D0 MOVE.B #$B3,D0 LSL #8,D0 MOVE.B #$B4,D0

Categories : Assembly

Using Global Variables in Y86 Assembly
I figured out why the registers were getting the wrong values (I was sending them the memory locations with irmovl instead of the values with mrmovl) and in a similar vein, how to assign the value to the global variable sum (rmmovl %eax, sum). It was a matter of addressing the content as opposed to location

Categories : Assembly


Recently Add
TASM checking arguments when cx is modified
copy certain characters from one string to another in assembly
How to initialize variables, compile and run GNU assembly program
[MASM]Another 'cannot use 16-bit register with a 32-bit address' error
Add 32-bit floats in eax/ecx registers?
Using scanf with x86 GAS assembly
Push and Pop in arm
creating a linked list in assembly language 8086
Assembler Print the number on the screen
Is there translate-table XLAT instruction in ARM programming?
Multiplying word size inputs x86
What does bx lr do in ARM assembly language?
AVR Assembler Labels
Differences of x86 and x86-64 machine code
What's wrong with x86 ENTER instruction?
Atmega328p ADC assembly doesn't convert
TASM extra characters when calling subroutine
Assembly 80286: Accessing n-th byte of variable
What is the difference between section and label in assembly in NASM?
jb in Assembly and value in register
x86 linux system call calling convention?
Mixing Assembly & Fortran plus parallelization (OpenMP)
How does xchg works with string for assembly x86?
Call C kernel from assembly bootloader
Create a File using ARM Assembly
SSE instructions in ASM function
How to calculate parity of a 32bits number in assembly?
Recursion function with pushing parameters not work correct
Assembly language procedure to take 2-digit input from the user
Changes value use in all functions (NASM)
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.