im having a PANIC when running some assembly in bochs - c

this image showcase the error im getting when running the command "bochs" in the bootDIr directory where my assembly file , the image ,the binary and the script are at , the tutorial i watched was using ubuntu while im using kali,i dont think that was relevant but i would love your help
the goal is to show the "Hello" String when booting (+some messages generated by the emulator)
here is the nasm code:
[BITS 16]
[ORG 0x7c00]
start :
xor ax,ax
mov ds,ax
mov es,ax
mov ss, ax
mov sp, 0x7c00
PrintMessage :
mov ah,0x13
mov al, 1
mov bx,0xa
xor dx,dx
mov bp, Message
mov cx, MessageLen
int 0x10
End :
hlt
jmp End
Message : db "Hello"
MessageLen : equ $-Message
times (0x1be -($-$$)) db 0
db 80h
db 0,2,0
db 0f0h
db 0ffh,0ffh,0ffh
dd 1
dd (20*16*63 - 1 )
times (16*3) db 0
db 0x55
db 0xaa

Related

Assembly and C project loop [duplicate]

This question already has answers here:
What does "int 0x80" mean in assembly code?
(9 answers)
Assembly (x86): <label> db 'string',0 does not get executed unless there's a jump instruction
(2 answers)
How to represent octal numbers in Assembly?
(2 answers)
How to make the kernel for my bootloader?
(1 answer)
Closed 3 months ago.
I am trying to get my C program to run on a computer with no operating system. I have a version of an MBR that just prints a (!), but when i try to add code to run my C program, as shown here the machine just reboots infinitely.
I only just got the assembly to compile because i took out some definitions and just put the numbers where it says //here
Here is my code:
`
[org 0x7c00]
mov [BOOT_DISK], dl
CODE_SEG equ GDT_code - GDT_start
DATA_SEG equ GDT_data - GDT_start
cli
lgdt [GDT_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp CODE_SEG:start_protected_mode
jmp $
GDT_start:
GDT_null:
dd 0x0
dd 0x0
GDT_code:
dw 0xffff
dw 0x0
db 0x0
db 0b10011010
db 0b11001111
db 0x0
GDT_data:
dw 0xffff
dw 0x0
db 0x0
db 0b10010010
db 0b11001111
db 0x0
GDT_end:
GDT_descriptor:
dw GDT_end - GDT_start - 1
dd GDT_start
[bits 32]
start_protected_mode:
mov al, '!'
mov ah, 0x0f
mov [0xb8000], ax
;open the file for reading
mov eax, 5
file_name db 'e.exe'
mov ebx, file_name
mov ecx, 0 ;for read only access
mov edx, 0777 ;read, write and execute by all
int 0x80
;read from file
mov eax, 3
mov ebx, 1 //here
mov ecx, 26 //here
mov edx, 26 //here
int 0x80
jmp $
BOOT_DISK: db 0
times 510-($-$$) db 0
dw 0xaa55
`

check positive number assembly8086

iam trying to write an assembly code 8086 i have two array X AND Y size 10 and i want to enter a number and check if its positive y will be 1 if negative it will be 0
but my code just displayed what i enter a number but i want it like this example .
example:
X : 2 -5 -7 8 -4 9 11 -12 90 -50
Y : 1 0 0 1 1 0 1 1 0 1 0
I wrote:
.MODEL SMALL
.DATA
x db 10 dup ("?")
y db 10 dup ("?")
.CODE
MOV AH,1
INT 21H
mov si,offset x
mov di,offset y
mov [si],al
cmp si,0
ja l1
jmp l2
l1 : mov al , 1
mov [di],al
jmp l3
l2 : mov ah , 0
mov y[di] , al
jmp l3
l3 :
MOV AH, 2
mov dl,al
INT 21H
cmp si,10
je l4
inc si
inc di
l4 :
.EXIT
END
The list of problems is long. Check out these comments and try to see why the error exists.
<<<< add label for a 10-time repeat
MOV AH,1
INT 21H
mov si,offset x <<<< move higher up for 1-time execution
mov di,offset y <<<< move higher up for 1-time execution
mov [si],al
cmp si,0 <<<< the byte to compare is in AL
ja l1 <<<< requires a SIGNED conditional, use JGE
jmp l2 <<<< reverse condition and drop this jump
l1 : mov al , 1
mov [di],al
jmp l3
l2 : mov ah , 0 <<<< should be AL
mov y[di] , al <<<< DI already refers to the y-array, use just [DI]
jmp l3 <<<< redundant
l3 :
MOV AH, 2
mov dl,al
INT 21H
cmp si,10 <<<< 10 is wrong
je l4
inc si <<<< move above checking iterator
inc di <<<< move above checking iterator
<<<< needs jumping back in order to repeat
l4 :
Next code, just like yours, inputs a single character from the keyboard and treats its ASCII code as the byte you want to store in the x array. For negative bytes you should input extended ASCII's. Use the Alt followed by a number up to 255.
.CODE
xor bx, bx
again:
mov ah, 01h ; DOS.GetCharacter
int 21h ; -> AL
mov x[bx], al
mov ah, 255
shl ax, 1
not ah
mov y[bx], ah ; 1 for positive, 0 for negative
inc bx
cmp bx, 10
jb again
.EXIT

Define and access an array in x86 assembly TASM

I am trying for hours and hours to access an array in assembly x86 TASM using dosbox - but I always get 'Operand types do not match' or 'Pointer expression needs brackets' error - I've searched the whole internet and couldn't find something that works in TASM x86.. this is the code:
IDEAL
MODEL small
STACK 100h
DATASEG
; --------------------------
A DB 1, 2, 3, 4, 5, 6, 7, 8, 10, 11
; --------------------------
CODESEG
start:
mov ax, #data
mov ds, ax
; --------------------------
mov al,A[0]
; --------------------------
exit:
mov ax, 4c00h
int 21h
END start
Changing the line to:
mov ax, BYTE PTR A[0]
or to:
mov ax, A[BYTE PTR 0]
And even changing ax or al with all these combinations is failing.. or trying to acces the OFFSET of array A:
mov al, A[OFFSET A]
I don't know where's the problem..
Thank you for helping!

x86 real mode: move data from one array to another

Here is my code:
data segment
gio db 1,2,3,4,5,6
ricxvi db 1
jami db 0
x db ?
ends
stack segment
db 128 dup(0)
ends
code segment
start:
MOV AX,DATA
MOV DS,AX
mov cx, 6
lea si, gio
mov ah, 0
n1:
mov al, [si]
cmp ricxvi, 3
je n2
jmp n3
n2:
add jami, al
mov ricxvi, 1
jmp n4
n3:
add ricxvi, 1
push ax
n4:
add si, 1
add di, 1
loop n1
mov ricxvi, 1
mov ax, 0
mov cx, 6
lea si, gio
n5:
cmp ricxvi, 3
je n6
jmp n7
n6:
mov ricxvi, 1
add si, 1
loop n5
n7:
pop [si]
add si, 1
loop n5
mov ax, 4c00h
int 21h
ends
end start
I have a array named gio And I'm trying to reverse this array but leave every 3th element on its position. Meaning I want to get the output like this 5,4,3,2,1,6 but As I inspect variables, in array I have 5,4,2,1,B8. I have noticed that when program first hits pop [si] whole array changes, exploring variables shows me that its 5, NULL, 3, 4, 5, 6 should it not be 5,2,3,4,5,6? I'm using emu8086. Question may sound silly as I'm new with assembly. Thanks.
There are three errors :
You are poping two bytes into [si] but you only need one byte. The solution is to pop two bytes into a register and move one byte into [si].
Under label n6 you got loop n5, but when cx becomes zero the loop doesn't jump and the block n7 is executed when it shouldn't.
You forgot to increase the "3" counter under label n7.
Here are the fixes :
n6:
mov ricxvi, 1
add si, 1
loop n5
jmp finale ;◄■■ SKIP NEXT BLOCK WHEN CX=0.
n7:
add ricxvi, 1 ;◄■■ INCREASE THE "3" COUNTER.
pop ax ;◄■■ POP TWO BYTES.
mov [si], al ;◄■■ USE ONE BYTE ONLY.
add si, 1
loop n5
finale: ;◄■■ END LABEL.
mov ax, 4c00h
int 21h

Assembly Language (Order Taker)

I'm trying hard to study Assembly language.
I really need help to store different 10 items in an array
I want to build a program that will accept items from 10 choices and it will store it.
Those 10 items have different value.
Example
Item 1 = 10$
Item 2 = 4$
So that when the User tries to choose Item1 and Item2 it will show the
sum of both items.
I'll be gladly be happy if someone can share his/her own code that can store 10 items with the sum of all items. Thanks
Here's my code:
_start:
mov eax,3 ;number bytes to be summed
mov ebx,0 ;EBX will store the sum
mov ecx, x ;ECX will point to the current element to be summed
top: add ebx, [ecx]
add ecx,1 ;move pointer to next element
dec eax ;decrement counter
jnz top ;if counter not 0, then loop again
done:
add ebx, '0'
mov [sum], ebx ;done, store result in "sum"
display:
mov edx,1 ;message length
mov ecx, sum ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
global x
x:
db 2
db 4
db 3
sum:
db 0
My code here does have problem.
x:
db 2
db 4
db 3
sum:
db 0
Since you've defined all of your variables to be of byte type, you must process them as bytes! You're reading and writing dwords in your program.
This could have been OK:
top: add bl, [ecx]
add ecx, 1 ;move pointer to next element
dec eax ;decrement counter
jnz top ;if counter not 0, then loop again
done:
add bl, '0'
mov [sum], bl ;done, store result in "sum"

Resources