assembly

Handling non-digit user input to a MARS read-integer system call?

独自空忆成欢 提交于 2021-02-05 12:00:36
问题 I'm doing a simple program of car park that takes the input from the user, and branch to a label in accordance of the input. The problem is, the program always ends abruptly if the user enter an input with different data type than integer (like "a" or any alphabets) Below is my code (that relevant to the input part) : li $v0,5 #system call to get input from user syscall li $t1,2 beq $v0,1,park # go to "park" section of codes if input is 1 beq $v0,2,exit # go to "exit" section of codes if

How does CPU perform operation that manipulate data that's less than a word size

≯℡__Kan透↙ 提交于 2021-02-05 11:39:49
问题 I had read that when CPU read from memory, it will read word size of memory at once (like 4 bytes or 8 bytes). How can CPU achieve something like: mov BYTE PTR [rbp-20], al where it copies only one byte of data from al to the stack. (given the data bus width is like 64 bit wide) Will be great if anyone can provide information on how it's implemented on the hardware level. And also, as we all know that when CPU execute program, it has program counter or instruction pointer that points to the

Moving a value of a lesser size into a register

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-05 11:38:22
问题 I have stored a one-byte value of 8 and I'd like to move that into the rax register. I'm currently doing this with movzx to zero-extend the byte: .globl main main: push %rbp mov %rsp, %rbp movb $8, -1(%rbp) movzx -1(%rbp), %rax <-- here ... How does the movzx instruction 'know' that the value at -1(%rbp) is only one byte long? From here is says, if I'm reading it properly, that it can work on both a byte and a word , but how would it know? For example, if I added a two-byte value at -2(%rbp)

NASM says “Invalid combination of opcode and operands”

北战南征 提交于 2021-02-05 11:36:26
问题 I just started learning assembly programming. I am using NASM on linux. I wrote this code that's basically meant to calculate the somethingth power of something and I know it's probably not exactly good, but I really don't care at this point, all I want is just SOME idea why I keep getting that error, because I have tried to modify and switch operands and operations and everything in the section where the problem is, but if anything that only gave me more error messages. As I said, I'm really

Calling the C-function _printf from NASM causes a Segmentation Fault

北城余情 提交于 2021-02-05 11:35:31
问题 I've been trying to learn 64-bit assembly on both Mac-OS and Windows using NASM. My code is extern _printf section .data msg db "Hello World!", 10, 0 section .text global _main _main: mov rax, 0 mov rdi, msg call _printf mov rax, 0x2000001 mov rdi, 0 syscall and I compile it with nasm -f macho64 -o main.o main.asm gcc -o main main.o While trying to call _printf , I got the error Segmentation fault: 11 When I remove the call to _printf , my code runs fine. Why does the call to _printf cause a

NASM says “Invalid combination of opcode and operands”

白昼怎懂夜的黑 提交于 2021-02-05 11:33:05
问题 I just started learning assembly programming. I am using NASM on linux. I wrote this code that's basically meant to calculate the somethingth power of something and I know it's probably not exactly good, but I really don't care at this point, all I want is just SOME idea why I keep getting that error, because I have tried to modify and switch operands and operations and everything in the section where the problem is, but if anything that only gave me more error messages. As I said, I'm really

Computing the factorial of 10 using 8086 assembly

寵の児 提交于 2021-02-05 10:43:06
问题 I have been trying to solve this using assembly language. The thing is I cannot store the 10! In al and my code works for finding factorial of 5. How do I store my result of 10! In a register? When I find factorial of 5 I can see the result clearly in al because 120 can be stored in al . Any help would be appreciated. Here's my code for 5! org 100h .DATA ANS DB ? .CODE MAIN PROC MOV AX,@DATA MOV DS,AX MOV AL,5 MOV CL,4 MOV BL,AL SUB BL,1 L: MUL BL SUB BL,1 LOOP L MOV ANS,AL END MAIN ret 回答1:

What's the difference between `add al, 0` and `add al, '0'`?

孤街浪徒 提交于 2021-02-05 10:40:39
问题 So I've been reading some assembly code for learning purposes and have come across these two instructions: add register, value add register, 'value' ; Where the value is now in single quotes What's the difference between the two? Before I get flamed if this happens to be a duplicate. I've asked here as I don't know exactly what to Google to answer this question. 回答1: Depending upon the assembler, enclosing a character in single quotes may request that the compiler use the ASCII code of that

Difference between adding 0 and moving a register in MIPS

心已入冬 提交于 2021-02-05 09:55:34
问题 What's the difference between: add rd, rs, zero and move rd, rs They both look like they should do the same thing. 回答1: The move is a pseudoinstruction, they do the same job. MIPS is a reduced instruction set computer (RISC), so the instruction size and hardware complexity are minimized by keeping the number of instructions small. However, MIPS defines pseudoinstructions that are not actually part of the instruction set but are commonly used by programmers and compilers. 来源: https:/

Reverse numbers in a variable [closed]

一笑奈何 提交于 2021-02-05 09:27:07
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 13 days ago . Improve this question I have to reverse 20 numbers in a variable (src) and put te result in another variable (dst) in ARM 7 but I can't do it. I have src = 1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4 and I want that dst = 4,3,2,1,8,7,6,5,4,3,2,1,8,7,6,5,4,3,2,1. Could someone help me please ? Here is