Sasquadge 0 Newbie Poster

So my program is supposed to ask the user for a hex and decode the Mpeg for the Version, Layer Description, and sampling rate. So My problem is getting the smapling rate any suggestions?

TITLE CS2650 Assembler Assignment #3 Template

; Student Name: Cody Squadroni
; Assignment Due Date: 11/25/2012

INCLUDE Irvine32.inc
.data
;--------- Enter Data Here
vSemester BYTE "Fall",0
vAssignment BYTE "Assembler",0
vName BYTE "Name",0
vMP3Header BYTE "Enter MP3 Frame Header in Hex: ",0
vMpeg25 BYTE "MPEG Version 2.5",0
vMpeg20 BYTE "MPEG Version 2.0",0
vMpeg10 BYTE "MPEG Version 1.0",0
vMpegRE BYTE "MPEG Reserved",0
vLayerRE BYTE "      Reserved",0
vLayerIII BYTE "      Layer III",0
vLayerII BYTE "      Layer II",0
vLayerI BYTE "      Layer I",0

.code
main PROC
;--------- Enter Code Below Here
    call Clrscr
    call DisplaySemester
    call DisplayAssignment
    call DisplayName
    call ReadMP3Header
    call DisplayVersion
    call DisplayLayer
    ;Call SamplingRate

;Semester
    DisplaySemester:
        mov dh, 12
        mov dl, 12
        call Gotoxy
        mov edx, OFFSET vSemester
        call    WriteString

;Assignment
    DisplayAssignment:
        mov dh, 13
        mov dl, 12
        call Gotoxy
        mov edx, OFFSET vAssignment
        call    WriteString

;Name
    DisplayName:
        mov dh, 14
        mov dl, 12
        call Gotoxy
        mov edx, OFFSET vName
        call    WriteString

;MP3 Header
    ReadMP3Header:
        mov dh, 16
        mov dl, 12
        call Gotoxy
        mov edx, OFFSET vMP3Header
        call    WriteString
        call    ReadHex

;Version
    DisplayVersion:
        mov ecx, eax
                ;AAAAAAAAAAABBCCDEEEEFFGHIIJJKLMM
        and eax, 00000000000110000000000000000000b
        shr eax, 19

        cmp eax, 00b
        jz dMpeg25

        cmp eax, 01b
        jz dMpegRE

        cmp eax, 10b
        jz dMpeg20

        mov edx, offset vMpeg10
        jmp DisplayString

    dMpeg25:
        mov edx, offset vMpeg25
        jmp DisplayString

    dMpegRE:
        mov edx, offset vMpegRE
        jmp DisplayString

    dMpeg20:
        mov edx, offset vMpeg20
        jmp DisplayString

    DisplayString:
        call WriteString

;Layer

    DisplayLayer:
        mov eax, ecx
                ;AAAAAAAAAAABBCCDEEEEFFGHIIJJKLMM
        and eax, 00000000000001100000000000000000b
        shr eax, 17

        cmp eax, 00b
        jz dLayerRE

        cmp eax, 01b
        jz dLayerIII

        cmp eax, 10b
        jz dLayerII

        mov edx, offset vLayerI
        jmp LayerDisplay

    dLayerRE:
        mov edx, offset vLayerRE
        jmp LayerDisplay

    dLayerIII:
        mov edx, offset vLayerIII
        jmp LayerDisplay

    dLayerII:
        mov edx, offset vLayerII
        jmp LayerDisplay

    LayerDisplay:
        call WriteString 

        ret
;Sampling Rating







call ReadChar
main ENDP

END main

Dani AI

Generated

— The sampling frequency is encoded as a 2‑bit index inside the 32‑bit MP3 frame header and must be interpreted relative to the MPEG version you already decode. Extract those two bits, reject the reserved index, and look up the actual Hz value from a small version-dependent table. Below are the exact tables and a compact MASM-style lookup approach you can drop into your program.

MPEG sampling-rate tables (index = two bits from the header):

  • MPEG‑1: 00 → 44100 Hz, 01 → 48000 Hz, 10 → 32000 Hz, 11 → reserved
  • MPEG‑2: 00 → 22050 Hz, 01 → 24000 Hz, 10 → 16000 Hz, 11 → reserved
  • MPEG‑2.5: 00 → 11025 Hz, 01 → 12000 Hz, 10 → 8000 Hz, 11 → reserved

Practical MASM pattern (assumes full 32‑bit header is in EAX and you previously computed a small versionID value: 3=MPEG1, 2=MPEG2, 0=MPEG2.5). The tables contain DWORDs that point to zero‑terminated strings so you can call WriteString directly.

; extract sample index (bits 11..10)
mov esi, eax
shr esi, 10        ; sample index now in low bits
and esi, 3         ; esi = 0..3

; choose table by versionID in BL (set earlier)
cmp bl, 3
je UseTblMPEG1
cmp bl, 2
je UseTblMPEG2
cmp bl, 0
je UseTblMPEG25
jmp BadVersion

UseTblMPEG1:
    lea edi, SampleTbl_MPEG1
    jmp IndexDone
UseTblMPEG2:
    lea edi, SampleTbl_MPEG2
    jmp IndexDone
UseTblMPEG25:
    lea edi, SampleTbl_MPEG25
    jmp IndexDone

IndexDone:
    mov ebx, esi
    shl ebx, 2            ; 4 bytes per pointer
    add edi, ebx
    mov edx, [edi]        ; edx -> string pointer
    call WriteString
    jmp Done

BadVersion:
    mov edx, OFFSET sInvalid
    call WriteString

Data layout example:

SampleTbl_MPEG1 DWORD OFFSET s44100, OFFSET s48000, OFFSET s32000, OFFSET sReserved
SampleTbl_MPEG2 DWORD OFFSET s22050, OFFSET s24000, OFFSET s16000, OFFSET sReserved
SampleTbl_MPEG25 DWORD OFFSET s11025, OFFSET s12000, OFFSET s8000, OFFSET sReserved
s44100 BYTE "44100",0
... sReserved BYTE "reserved",0

Troubleshooting tips: confirm ReadHex returns the full 32‑bit header in the register you expect; test with known headers; explicitly handle index = 3 (reserved) and the reserved/invalid version code; and use WriteInt if you prefer numeric output instead of string table entries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.