Can I sum different bits (8 bit with 1开发者_运维问答6 bit) number in assembly?
For example;
sums proc near
mov ax,0280h
mov bh,30h
mov ch,20h
adc ax,bh
adc ax,ch
ret
sums endp
This code gives an error; "operant types dont match"
Sure. Just load the 8-bit value into a register and sign-extend or zero-extend it. Then add.
Of course.
mov ax,33h
mov cx,1133h
add ax,cx
This is a shot in the dark, so correct me if I'm wrong (NASM - AT & T syntax)
.section .text
.globl _start
_start:
movl $0, %eax
mov $0x280, %ax
movl $0, %ebx
movl $0, %ecx
mov $0x30, %bh
mov $0x20, %ch
add %bx, %ax
add %cx, %ax
movl %eax, %ebx # store the result in %ebx
movl $1, %eax # syscall for exit()
int $0x80
If you are on Linux, after running this application on the console, execute:
echo $?
to print the return code of the app, which is actually the sum we did before (and stored in %ebx
).
Change
mov bh,30h
mov ch,20h
adc ax,bh
adc ax,ch
to
mov bx,30h
mov cx,20h
adc ax,bx
adc ax,cx
精彩评论