Assembler Factorial 16 bits in https://parraman.github.io/asm-simulator/

29 Views Asked by At

Here's the problem statement in English:

"I have a problem with my 16-bit assembler code in the emulator for a Factorial Program:

JMP boot 
JMP isr     ; Interrupt vector
JMP svc     ; System call vector

sStackTop   EQU 0x0FF   ; Initial Supervisor SP
uStackTop   EQU 0x1FF   ; Initial User Task SP
txtDisplay  EQU 0x2E0

keypressed:     ; 1 = key pressed
    DB 0        ; 0 = No key pressed

value:          ; The number of the
    DB 0        ; key pressed in ASCII

boot:
    ; ... (Boot, isr, and svc code remains unchanged) ...

    ORG 0x100   ; Following instructions
                ; will be assembled at 0x100

task:           ; The user task
    MOV A, 0
    MOV B, 0
loop:
    CALL readchar   ; Polls the keypad
    CMPB AH, 1      ; using readchar
    JNZ loop
    MOVB BL, AL     ; If key was pressed use
    CALL factorial  ; calculate factorial
    JMP loop 

readchar:       ; User space wrapper
    ; ... (readchar and putchar code remains unchanged) ...

factorial:
    MOV CX, BL      ; Set the value for which to calculate factorial
    MOV AX, 1       ; Initialize the result to 1

    FACTORIAL_LOOP:
    MUL CX          ; Multiply AX by CX
    DEC CX          ; Decrement CX
    JNZ FACTORIAL_LOOP  ; Jump to FACTORIAL_LOOP if CX is not zero

    MOVB BL, AL     ; Move the result to BL register
    CALL putchar    ; print the result
    RET  ; Error 38: Error: MOV does not support these operands

I have tried everything but it's not working. The idea is to capture the number, calculate its factorial, and display it in the output."

The error message is "Error: MOV does not support these operands."

this is link https://parraman.github.io/asm-simulator/

I tried to modify the MOV instruction in the factorial subroutine to move the result to the BL register, which is a byte-sized register, using MOVB BL, AL. However, the assembler returned an error "Error: MOV does not support these operands" indicating that the assembler does not support moving data between byte-sized and word-sized registers directly with the MOV instruction.

What I was expecting was that the MOVB BL, AL instruction would move the lower byte of the AX register (which contains the factorial result) into the BL register, allowing me to print the result using the putchar subroutine.

enter image description here

0

There are 0 best solutions below