(b) Write and run a program using 8086 assembly language which finds the highest of four byte values stored in memory. The highest value should be left in AL register

, , No Comments

 Certainly! Below is an example of an 8086 assembly language program that finds the highest of four byte values stored in memory and leaves the highest value in the AL register:


```assembly

section .data

    values db 45h, 32h, 7Eh, 21h  ; Replace these values as needed


section .text

    global _start


_start:

    mov al, [values]    ; Load the first byte into AL

    mov bl, [values+1]  ; Load the second byte into BL

    cmp al, bl           ; Compare the first and second bytes

    jge check_next       ; Jump to check_next if AL >= BL

    mov al, bl           ; Move the value of BL to AL if BL > AL


check_next:

    mov bl, [values+2]  ; Load the third byte into BL

    cmp al, bl           ; Compare the current highest value (AL) with the third byte

    jge check_last       ; Jump to check_last if AL >= BL

    mov al, bl           ; Move the value of BL to AL if BL > AL


check_last:

    mov bl, [values+3]  ; Load the fourth byte into BL

    cmp al, bl           ; Compare the current highest value (AL) with the fourth byte

    jge exit_program     ; Jump to exit_program if AL >= BL

    mov al, bl           ; Move the value of BL to AL if BL > AL


exit_program:

    ; Add any additional code here if needed


    ; Exit the program

    mov eax, 1           ; System call number for sys_exit

    xor ebx, ebx         ; Exit code 0

    int 0x80             ; Call kernel

```


This program uses a series of comparisons to find the highest value among the four bytes in the `values` array. Replace the values in the `values` array with your desired byte values. Compile and run the program using an assembler and linker, as explained in the previous response.

0 टिप्पणियाँ:

Post a Comment