w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » ASSEMBLY » Page 1
In MIPS/SPIM, whats the difference between li and lw?
A word is a fixed-length sequence of bits.On MIPS32, a word is 32 bits wide.The instruction lw $regA, offset($regB) loads a word from the memory location specified by offset($regB) into register regA.By contrast, li reg, immediate is not a true instruction. No MIPS cpu can execute li. It's a pseudo-instruction that is turned into a sequence of two instructions by the assembler: lui $reg, [most si

Categories : Assembly

Assembly working with strings, checking result
If you want to check the correctness of your hand-written assembly implementation (which is a really good idea), you can write the equivalent program in a different language. Give both programs the same input, pipe each output into a file, and run a diff-utility on the files.If you want to trace your program though its execution, you can run the program in a debugger. It won't have the amenities o

Categories : Assembly

NASM Assembler, how to define label twice?
With local labels. Local labels start with a dot. Someproc: .Somelabel: Ret Anotherproc: .Somelabel: Ret They are visible to the proc they are in. You can access them from anywhere by prefixing them with the proc name. Someproc: .Somelabel: Ret Anotherproc: .Somelabel: jmp Someproc.Somelabel

Categories : Assembly

What does this line of assembly code do?
Yes, that's exactly what it does. The dword ptr modifier is redundant here because the register is already 32 bits, but it is sometimes necessary to tell the assembler what type of data it should be working on when it can't be directly inferred. For example push dword ptr [edx + 15Ch]

Categories : Assembly

Swap vga text screen halves using x86 assembly
Your inner loop does the swapping wrong. The first block copies a character from column c in the top half to the bottom half, then the second block copies the character from column c+1 in the bottom to column c in the top. To swap, you should read the same column from both halves and write them back swapped. Such as: MOV AL, [SI] MOV BL, [DI] MOV [SI], BL MOV [DI], AL ADD DI, 2 ADD SI, 2 Also

Categories : Assembly

Decimal to binary in 32 bit assembly (IA-32)
It appears that what you're actually doing is changing a string which contains an ASCII representation of a decimal number into the equivalent number in a register. The typical way to do this is to start with the most significant digit and repeatedly multiply the previous result by ten and add the digit's value. In psuedo-code: value = 0 for each digit, starting with the most significant: v

Categories : Assembly

Access writing violation when using INVOKE
main PROC INVOKE minmax, OFFSET array, LENGTHOF array, OFFSET msg1, OFFSET msg2 main ENDP Look at your proc carefully... Your missing something, do you realize what? Well, your missing a ret right before main endp! Without a ret the cpu will continue executing what ever is after main endp. main PROC INVOKE minmax, OFFSET array, LENGTHOF array

Categories : Assembly

Writing to a file in Assembly file descriptor trouble
src_file resb 1 ; Source file descriptor dest_file resb 1 ; Destination file descriptor 1 byte for the file descriptors will not cut it. They need to be DWORD sized variables! src_file resd 1 ; Source file descriptor dest_file resd 1 ; Destination file descriptor Why would the program show an error? You never told it to! This is Assembly, nothing is automati

Categories : Assembly

Linking in assembly files with Mingw
Do symbol names in asm files begin with _ (underscore)? For example following example compiled with gcc 4.9.2 from MinGW-W64 works as expected on 32-bit XP: ----- file asmtest.c ----- #include <stdio.h> extern int add(int x, int y); int main(int argc, char *argv[]) { printf("The result is: %d ", add(3, 5)); return 0; } ----- file asmadd.S ----- .section .text .global _add _add:

Categories : Assembly

What is the usage for the shadow space for the first 4 parameters in x64 calling convention
The callee may or may not need to save them, that depends entirely on the situation. For example, a function that just returns the sum of the arguments might not need to save them. In this case using registers saves a store and a load, while it does not incur any overhead in the other case (the store is just moved from the caller to the callee). Allocating the shadow space is practically free if

Categories : Assembly

Representations in bases assembly language 8086
128 is = 1111111111000000 That's not correct. The 16-bit number 128 would be 0000000010000000. If you meant -128 then that would be 1111111110000000 (note that there's one 1 less than in your version). I didn't know how to transform in base 16 Just take your binary representations and map each group of four bits to a hexadecimal digit: Base2 Base16 ------------- 0000 0 0001 1 00

Categories : Assembly

definition for data types in assembly language
Many assemblers use a ? like myVar db ? to clearly show you don't care about the initialization value. But even then most of the time the space will be filled with zeroes.

Categories : Assembly

Why does jmpq of x86-64 only need 32-bit length address?
The E9 opcode in 64 bit mode take a 32 bit sign displacement sign extended to 64 bits: E9 cd -> JMP rel32 ->Jump near, relative, RIP = RIP + 32-bit displacement sign extended to 64-bits The FF opcode can be used to jump to a 64 bit address: FF /4 -> JMP r/m64 -> Jump near, absolute indirect, RIP = 64-Bit offset from register or memory Quotes taken from the Intel instruction set manua

Categories : Assembly

Status Flags when comparing two values
You can look at the eflags register in a debugger (like gdb). There is plenty of readily accessible documentation about eflags, but essentially bits in the register are 0 or 1 depending on whether particular status flags are set. If it is not enough to just see the values in a debugger, and you need to do something with them: you can push eflags onto the stack (pushfl works for me) and then po

Categories : Assembly

Incorrect x8086 assembly language
dw is the assembler directive for define word. Now the length of a word may differ by machine, but in this case it is 2 bytes. You are storing three of these words (7, 5, and 2), so they will take up 6 bytes. db is the assembler directive for define byte, and $ means the current offset. As you are at offset 6 where this command appears, x is given the value 6. Using db to store the current

Categories : Assembly

How to far jump to $0x9000:%ax using AT&T syntax?
In x86 there is no such instruction you are attempting to do. What you need to do is to store the memory address 0x9000:ax into memory and then do an indirect jump to that address. The indirect jump is this one (Intel® 64 and IA-32 architectures software developer's manual combined volumes: 1, 2A, 2B, 2C, 3A, 3B, and 3C): FF /5 JMP m16:16 Jump far, absolute indirect, address given in m16:16 S

Categories : Assembly

x64 assembler for system programming
If you're running windows, Visual Studio Express (which is free) includes ml64.exe, a 64 bit assembler. A custom build step is needed to invoke ml64.exe, which I think you'll get prompted for the first time you try this, but I create the step manually. I first create an empty project, then choose project, properties, configuration manager, < new >, and select x64 to produce a 64 bit executable.

Categories : Assembly

SCSI Packets from USB
1) firmware can be placed most anywhere in the drive's memory... are you wondering how to access it? 2) afaik there is a universal standard for scsi packets (check wikipedia: http://en.wikipedia.org/wiki/SCSI#SCSI_command_protocol) 3) the packets are firmware and can only be modified through painstaking disassembly

Categories : Assembly

Copying string in reverse order using push and pop in Assembly,can't see output by calling writeString
Reversing a string does not make it any longer or shorter. You need to initialize the destination the same way you setup the source. string BYTE "kashif",0 dest BYTE "xxxxxx",0 Here the lengthof operator returns 7 because it will include the terminating zero. That terminating zero is not a byte you want to include in the reversing operation and so you must decrement the count. mov ecx,le

Categories : Assembly

Assembly 8086 : Strange behavior of the system time
I tried your code last night and it performed correctly. I got thousands of zeroes, ones and twoes and a single three. Your program has an obvious way to run just 1 time if the exit value of function 2Dh were anything else than 0. Under a real DOS exit values should only be 0 or 255. Did you try comparing with 255 and jumping if equal? Furthermore you could differentiate between a normal exit and

Categories : Assembly

NDK x86_64 giving reloc error when trying to link in x64 assembly language
-fPIC of course has no effect on hand written assembly code, it's a flag for the C compiler instructing it to generate position independent code. In this scenario, you are the compiler, so you have to write PIC yourself. Luckily, x86-64 helps you with it by providing a new RIP-relative addressing mode. As such, you just need to replace lea rcx,myprivatedata with lea rcx,[rip+myprivatedata].

Categories : Assembly

CISC vs MIPS do the same job example
If you just want to look at code for difference processors you can use this: http://ellcc.org/blog/?page_id=340 You can enter code you'd like to see compiled, choose a target, and then hit "Compile Source Code" to see the results.

Categories : Assembly

SPIM print ascii char
You write 3. Store them on the stack. Since you are allowed to use everything excepted a call of print_int why don't you store them in succesive memory bytes before using print_string to ouput the result.

Categories : Assembly

Accessing MMU/TLB at boot on Microblaze
The problem is that you're setting wrong bit. Many reference guides describing BigEndian architecture assume that bit #31 is 2^0 and bit #0 is 2^31. MicroBlaze manual is one of those using this confusing notation. In your case if you want to set bit VM (BigEndian bit 18) you need to set msr to 0x00002000 or 1 << (31-18). So basically changing line: ori r1, r1, 0x00002000 mts rmsr, r1 nop

Categories : Assembly

Assembly 8086 square root
Here you go: .data? int64 dq ? squareRoot dd ? .code fild int64 ;load the integer to ST(0) fsqrt ;compute square root and store to ST(0) fistp squareRoot ;store the result in memory (as a 32-bit integer) and pop ST(0) found here: Sqrt of 32bit number You will also find lots of help here: Calculate Sqrt in MASM

Categories : Assembly

Assembly Language symbol table
done is wrong, it's just 3 bytes after next2. The rest looks okay, but you also missed min and max which were declared using the .comm directive on lines 4 and 5.

Categories : Assembly

Using the LDS and LES instructions
Example microsoft style code meant for msdos or dos console windows that support 16 bit real mode dgroup group _data,_bss,stack _data segment public 'data' x dw 10 y dw 15 adr_x dd x adr_y dd y _data ends _bss segment public 'bss' _bss ends stack segment stack 'stack' dw 2048 dup (?) ; stack stack ends _text segment pa

Categories : Assembly

Practical uses for rotate carry left/right
If you want to shift bits out of one operand, and into another: SHL EAX, 1 ; move sign bit of EAX ... RCL EDX ; into LSB of EDX If you wanted to reverse the bits in EAX: MOV ECX, 32 loop: SHR EAX, 1 RCL EDX DEC ECX JNE LOOP ; EDX == EAX with bits reversed here The real point is that these rotate instructions capture "bits"

Categories : Assembly

fpu ia-32, floating point exception
+1 for searching SO and using a debugger, -1 for not reading the instruction set reference ;) The div r/m32 variant that you are using divides the 64 bit quantity formed from edx (top 32 bits) and eax (low 32 bits). Furthermore, you also get this exception if your result is out of range. The problem is you are not zeroing edx so it has some random value which causes the whole division to overflow

Categories : Assembly

Addressing Main Storage: What is the difference between D(B) and D(X,B)?
The distinction is most interesting when there is also a scale involved. I'll use Intel syntax here because that's what I am most familiar with. If you have an instruction on the form mov eax, [ebx+esi*4] Then that generalizes to instr target, [base+index*scale] Base, then, hold the address where the array (typically) is located in memory, index is the zero-based array element number in t

Categories : Assembly

What does this bsr.l instruction do?
I think these might be the result of a compiler optimization for more compact code. See "Short BRA Optimization" in the compiler guide. Recent IDA versions disassemble such branches as skip2 (there is also skip1) for HC08 and HC12 code. I haven't seen such optimization in ColdFire code before. EDIT: or it could be just an object file with unresolved relocations.

Categories : Assembly

Segmentation fault in my NASM program(I need a bit of help)
This is very strange: push ecx ret I guess you don't want the function to return to an address which is determined by ECX. Typically results of a function are returned in EAX. So change it to: mov eax, ecx ret and handle it appropriate after call outter. Looking at the following lines I suggest: call outter push eax It's a good idea to clear the stack, when that value isn't needed anymore

Categories : Assembly

NASM x86_64 scanf segmentation fault
The x86-64 calling convention doesn't push the arguments generally. Additionally you have to tell a function with variable count of arguments, how many floating point arguments you provide. This works: global main extern printf, scanf section .data msg: db "Enter a number: ",10,0 format:db "%d",0 section .bss number resb 4 section .text main: mov rdi, msg mov al, 0 call prin

Categories : Assembly

Accessing Array Elements in Assembly x86
If your AverageFunc is supposed to return EAX only then you still have to push and pop EDX. These 2 don't go together add eax, [edi] ;add value to total inc edi ;go to next point in the array Since EDI points to a double word you need to raise EDI by 4 in stead of 1. Also the addition will soon overflow. Solve it with add eax,[edi] adc edx,0 As a precaution put a suitable jecxz rig

Categories : Assembly

Parentheses in movl and dereferencing
You seem to think that there are two levels of indirection, but there's only one. That is, an address is formed by -4 + %ebp (note: the value of %ebp is used here, not the value it points to), and %eax is stored in memory at that address. So if %ebp == 100 you'd end up writing to address 100-4, which is 96.

Categories : Assembly

NASM subroutines and segmentation fault
At least 2 problems there: The push ecx should not be part of the subroutine, because that is already code in the main program. It sets up the buffer for printing via the write system call. Its location is used by the mov ecx, esp line. Note that ret pops off an address from the stack, and returns there. As such, in this case it will pop off your ecx value and try to use it as the return address

Categories : Assembly

possible for a procedure to have an argument?
Your question is if something like this is possible: call my_function, arg1, arg2 If this is your question you didn't completely understand the concepts of assembler and the functionality of the CPU, yet: In assembler code one assembler instruction typically equals one CPU instruction. CPUs do not have the concept of function arguments at all. Function arguments are a concept of higher-level p

Categories : Assembly

What is the advantage of using segment registers (today)?
Arguably, x86-64 long mode is the technology of "today". There classical segmentation for the most part is nonexistent, with only FS and GS being used for practical purposes. FS is typically used for various thread-local and system data in user mode, while GS is used for kernel mode. This latter use is supported by the SWAPGS instruction.

Categories : Assembly

Get structure size within MASM
I'm assuming that you'll be declaring the struct in your assembly code.According to the masm32 documentation you've got the following operators available to you: LENGTHOF variable SIZEOF variable SIZEOF type LENGTH expression SIZE expression Description The LENGTHOF operator returns the number of data items allocated for <variable>. The SIZEOF operator returns the total number

Categories : Assembly




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.